Skip to content

Commit 63771f5

Browse files
brustolinphilipphofmannlizokm
authored
feat(apple): SwiftUI documentation (#6046)
SwiftUI documentation Co-authored-by: Philipp Hofmann <[email protected]> Co-authored-by: Liza Mock <[email protected]>
1 parent ad8139d commit 63771f5

File tree

4 files changed

+77
-0
lines changed

4 files changed

+77
-0
lines changed

src/platform-includes/getting-started-config/apple.mdx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,10 @@ SentrySDK.start { options in
8181
}];
8282
```
8383
84+
## Use Sentry with SwiftUI
85+
86+
If you want to find out the performance of your Views in a SwiftUI project, [try the SentrySwiftUI library](/platforms/apple/performance/instrumentation/swiftui-instrumentation).
87+
8488
## Provide Debug Information {#debug-symbols}
8589
8690
Before capturing crashes, you need to provide debug information to Sentry. Debug information is provided by <PlatformLink to="/dsym">uploading dSYM files</PlatformLink>.
Loading
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
---
2+
title: SwiftUI Instrumentation
3+
sidebar_order: 12
4+
description: "Learn how to monitor the performance of your SwiftUI views."
5+
---
6+
7+
<Include name="beta-note.mdx" />
8+
9+
You can monitor the performance of your views in a SwiftUI project with the SentrySwiftUI library, which you can install via <PlatformLink to="/install/swift-package-manager/">SPM (Swift package manager)</PlatformLink>.
10+
11+
> If you plan to add _SentrySwiftUI_, you don`t need to also add _Sentry_ library since the former dependents on the latter.
12+
13+
In order to start monitoring the performance of your views, you need to wrap it with `SentryTracedView`, like this:
14+
```swift {tabTitle:Swift}
15+
16+
import SentrySwiftUI
17+
18+
var body: some View {
19+
SentryTracedView("<Name of your view>"){
20+
List {
21+
// Your SwiftUI code ...
22+
}
23+
}
24+
}
25+
```
26+
27+
You may omit the transaction name, Sentry will use the root view type as name, in the previous example the transaction name would be `List`.
28+
29+
Alternatively, you can use a modifier like this:
30+
31+
```swift {tabTitle:Swift}
32+
33+
import SentrySwiftUI
34+
35+
var body: some View {
36+
List {
37+
// Your SwiftUI code ...
38+
}.sentryTrace("<Name of your view>")
39+
}
40+
```
41+
42+
It is possible to use nested `SentryTracedView` to have a more granular transaction.
43+
44+
45+
```swift {tabTitle:Swift}
46+
47+
import SentrySwiftUI
48+
49+
var body: some View {
50+
SentryTracedView("My Awesome Screen"){
51+
HStack {
52+
SentryTracedView("Menu") {
53+
List{
54+
// Your SwiftUI code ...
55+
}
56+
}
57+
SentryTracedView("Content") {
58+
VStack{
59+
// Your SwiftUI code ...
60+
}
61+
}
62+
}
63+
}
64+
}
65+
```
66+
67+
This is the result
68+
69+
![Transaction with nested traced views](nested-view-transaction.png)

src/wizard/apple/ios.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,3 +108,7 @@ SentrySDK.start { options in
108108
options.enableMetricKit = true
109109
}
110110
```
111+
112+
## Performance Monitoring for SwiftUI
113+
114+
If you want to find out the performance of your Views in a SwiftUI project, [try the SentrySwiftUI library](/platforms/apple/performance/instrumentation/swiftui-instrumentation).

0 commit comments

Comments
 (0)