Skip to content

Commit 116d8f8

Browse files
committed
wip
1 parent 54f570b commit 116d8f8

File tree

1 file changed

+50
-49
lines changed

1 file changed

+50
-49
lines changed

Sources/IssueReporting/Documentation.docc/Articles/GettingStarted.md

Lines changed: 50 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ Learn how to report issues in your application code, and how to customize how is
55
## Reporting issues
66

77
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:
1010

1111
```swift
1212
guard let lastItem = items.last
@@ -19,68 +19,69 @@ else {
1919

2020
By default, issues are reported as purple runtime warnings in Xcode when your app is run on a
2121
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.
2323

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.
2828

2929
## Issue reporters
3030

3131
The library comes with a variety of issue reporters that can be used right away:
3232

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.
3939

4040
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,
4242
``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.
4444

4545
## Overridding issue reporters
4646

4747
By default the library uses the ``IssueReporter/runtimeWarning`` reporter, but it is possible to
4848
override the reporters used. There are two primary ways:
4949

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:
5253

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+
```
6959

70-
```swift
71-
import IssueReporting
72-
import SwiftUI
60+
or to temporarily add a new issue reporter:
7361

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
7865
}
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+
}
8183
}
82-
}
83-
```
84+
```
8485

8586
## Unimplemented closures
8687

@@ -131,7 +132,7 @@ struct MyApp: App {
131132
var body: some Scene {
132133
ParentView(
133134
model: ParentModel(
134-
child: ChildModel(onDelete: { ??? })
135+
child: ChildModel(onDelete: { /* ??? */ })
135136
)
136137
)
137138
}
@@ -145,7 +146,7 @@ upon initializing of `ChildModel`:
145146
@Observable
146147
class ChildModel {
147148
var onDelete: () -> Void = {}
148-
149+
// ...
149150
}
150151
```
151152

@@ -165,14 +166,14 @@ the `onDelete` closure, which will subtly break your feature.
165166

166167
The fix is to strike a balance between the restrictiveness of requiring the closure and the
167168
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:
170171

171172
```swift
172173
@Observable
173174
class ChildModel {
174175
var onDelete: () -> Void = unimplemented("onDelete")
175-
176+
// ...
176177
}
177178
```
178179

0 commit comments

Comments
 (0)