@@ -5,8 +5,8 @@ Learn how to report issues in your application code, and how to customize how is
5
5
## Reporting issues
6
6
7
7
The primary tool for reporting an issue in your application code is the
8
- `` reportIssue(_:fileID:filePath:line:column:) `` function. You can invoke from anywhere with your
9
- features' code to signal that something happened that should not have:
8
+ [ ` reportIssue ` ] ( < doc: reportIssue(_:fileID:filePath:line:column:)> ) function. You can invoke from
9
+ anywhere with your features' code to signal that something happened that should not have:
10
10
11
11
``` swift
12
12
guard let lastItem = items.last
@@ -19,68 +19,69 @@ else {
19
19
20
20
By default, issues are reported as purple runtime warnings in Xcode when your app is run on a
21
21
simulator or device, and as test failures when run in a testing context. Further, the test failures
22
- work in both Swift's native Testing framework, as well as Xcode 's older XCTest framework.
22
+ work in both Swift's native Testing framework, as well as Apple 's older XCTest framework.
23
23
24
- This allows you to report issues in your app that are less obtrusive than asserts, which crash
25
- your app immediately, but also more noticeable than printing to the console, which is easy to miss.
26
- And by raising test failures in testing contexts you can even verify certain code paths are
27
- not executed via unit tests.
24
+ This gives you the ability to report issues in your app that are less obtrusive than ` assert ` s,
25
+ which crash your app immediately, but also more noticeable than printing to the console, which is
26
+ easy to miss. And by raising test failures in testing contexts you can even automatically verify
27
+ that certain code paths are not executed in your unit tests.
28
28
29
29
## Issue reporters
30
30
31
31
The library comes with a variety of issue reporters that can be used right away:
32
32
33
- * `` IssueReporter/runtimeWarning `` : Issues are reported as purple runtime warnings in Xcode and
34
- printed to the console on all other platforms.
35
- * `` IssueReporter/breakpoint `` : A breakpoint is triggered, stopping execution of your app.
36
- This gives you the ability to debug the issue.
37
- * `` IssueReporter/fatalError `` : A fatal error is raised and execution of your app is
38
- permanently stopped.
33
+ * `` IssueReporter/runtimeWarning `` : Issues are reported as purple runtime warnings in Xcode and
34
+ printed to the console on all other platforms. This is the default reporter .
35
+ * `` IssueReporter/breakpoint `` : A breakpoint is triggered, stopping execution of your app. This
36
+ gives you the ability to debug the issue.
37
+ * `` IssueReporter/fatalError `` : A fatal error is raised and execution of your app is permanently
38
+ stopped.
39
39
40
40
You an also create your own custom issue reporter by defining a type that conforms to the
41
- `` IssueReporter `` protocol. It has one requirement,
41
+ `` IssueReporter `` protocol. It has one requirement,
42
42
`` IssueReporter/reportIssue(_:fileID:filePath:line:column:) `` , which you can implement to report
43
- the issue in any way you want.
43
+ issues in any way you want.
44
44
45
45
## Overridding issue reporters
46
46
47
47
By default the library uses the `` IssueReporter/runtimeWarning `` reporter, but it is possible to
48
48
override the reporters used. There are two primary ways:
49
49
50
- * You can temporarily override reporters for a lexical scope using
51
- `` withIssueReporters(_:operation:)-91179 `` . For example, to turn off reporting entirely you can do:
50
+ * You can temporarily override reporters for a lexical scope using
51
+ `` withIssueReporters(_:operation:)-91179 `` . For example, to turn off reporting entirely you can
52
+ do:
52
53
53
- ``` swift
54
- withIssueReporters ([]) {
55
- // Any issues raised here will not be reported.
56
- }
57
- ```
58
-
59
- …or to temporarily add a new issue reporter:
60
-
61
- ``` swift
62
- withIssueReporters (IssueReporters.current + [.breakpoint ]) {
63
- // Any issues reported here will trigger a breakpoint
64
- }
65
- ```
66
-
67
- * You can also override the issue reporters globally by setting the `` IssueReporters/current ``
68
- variable. This is typically best done at the entry point of your application:
54
+ ``` swift
55
+ withIssueReporters ([]) {
56
+ // Any issues raised here will not be reported.
57
+ }
58
+ ```
69
59
70
- ``` swift
71
- import IssueReporting
72
- import SwiftUI
60
+ … or to temporarily add a new issue reporter:
73
61
74
- @main
75
- struct MyApp : App {
76
- init () {
77
- IssueReporters.current = [.fatalError ]
62
+ ```swift
63
+ withIssueReporters (IssueReporters.current + [.breakpoint ]) {
64
+ // Any issues reported here will trigger a breakpoint
78
65
}
79
- var body: some Scene {
80
- // ...
66
+ ```
67
+
68
+ * You can also override the issue reporters globally by setting the ``IssueReporters/ current``
69
+ variable. This is typically best done at the entry point of your application:
70
+
71
+ ```swift
72
+ import IssueReporting
73
+ import SwiftUI
74
+
75
+ @main
76
+ struct MyApp : App {
77
+ init () {
78
+ IssueReporters.current = [.fatalError ]
79
+ }
80
+ var body: some Scene {
81
+ // ...
82
+ }
81
83
}
82
- }
83
- ```
84
+ ```
84
85
85
86
## Unimplemented closures
86
87
@@ -131,7 +132,7 @@ struct MyApp: App {
131
132
var body: some Scene {
132
133
ParentView (
133
134
model : ParentModel (
134
- child : ChildModel (onDelete : { ??? })
135
+ child : ChildModel (onDelete : { /* ??? */ })
135
136
)
136
137
)
137
138
}
@@ -145,7 +146,7 @@ upon initializing of `ChildModel`:
145
146
@Observable
146
147
class ChildModel {
147
148
var onDelete: () -> Void = {}
148
- …
149
+ // ...
149
150
}
150
151
```
151
152
@@ -165,14 +166,14 @@ the `onDelete` closure, which will subtly break your feature.
165
166
166
167
The fix is to strike a balance between the restrictiveness of requiring the closure and the
167
168
laxness of making it fully optional. By using the library's
168
- `` unimplemented(_:fileID:filePath:function:line:column:)-1hsov `` tool we can mark the closure
169
- as unimplemented:
169
+ [ ` unimplemented ` ] ( < doc: unimplemented(_:fileID:filePath:function:line:column:)-1hsov> ) tool we can
170
+ mark the closure as unimplemented:
170
171
171
172
``` swift
172
173
@Observable
173
174
class ChildModel {
174
175
var onDelete: () -> Void = unimplemented (" onDelete" )
175
- …
176
+ // ...
176
177
}
177
178
```
178
179
0 commit comments