|
1 |
| -#if DEBUG && canImport(os) |
2 |
| - import os |
| 1 | +#if DEBUG |
| 2 | + #if canImport(os) |
| 3 | + import os |
3 | 4 |
|
4 |
| - // NB: Xcode runtime warnings offer a much better experience than traditional assertions and |
5 |
| - // breakpoints, but Apple provides no means of creating custom runtime warnings ourselves. |
6 |
| - // To work around this, we hook into SwiftUI's runtime issue delivery mechanism, instead. |
7 |
| - // |
8 |
| - // Feedback filed: https://gist.github.com/stephencelis/a8d06383ed6ccde3e5ef5d1b3ad52bbc |
9 |
| - let rw = ( |
10 |
| - dso: { () -> UnsafeMutableRawPointer in |
11 |
| - let count = _dyld_image_count() |
12 |
| - for i in 0..<count { |
13 |
| - if let name = _dyld_get_image_name(i) { |
14 |
| - let swiftString = String(cString: name) |
15 |
| - if swiftString.hasSuffix("/SwiftUI") { |
16 |
| - if let header = _dyld_get_image_header(i) { |
17 |
| - return UnsafeMutableRawPointer(mutating: UnsafeRawPointer(header)) |
| 5 | + // NB: Xcode runtime warnings offer a much better experience than traditional assertions and |
| 6 | + // breakpoints, but Apple provides no means of creating custom runtime warnings ourselves. |
| 7 | + // To work around this, we hook into SwiftUI's runtime issue delivery mechanism, instead. |
| 8 | + // |
| 9 | + // Feedback filed: https://gist.github.com/stephencelis/a8d06383ed6ccde3e5ef5d1b3ad52bbc |
| 10 | + let rw = ( |
| 11 | + dso: { () -> UnsafeMutableRawPointer in |
| 12 | + let count = _dyld_image_count() |
| 13 | + for i in 0..<count { |
| 14 | + if let name = _dyld_get_image_name(i) { |
| 15 | + let swiftString = String(cString: name) |
| 16 | + if swiftString.hasSuffix("/SwiftUI") { |
| 17 | + if let header = _dyld_get_image_header(i) { |
| 18 | + return UnsafeMutableRawPointer(mutating: UnsafeRawPointer(header)) |
| 19 | + } |
18 | 20 | }
|
19 | 21 | }
|
20 | 22 | }
|
21 |
| - } |
22 |
| - return UnsafeMutableRawPointer(mutating: #dsohandle) |
23 |
| - }(), |
24 |
| - log: OSLog(subsystem: "com.apple.runtime-issues", category: "ComposableArchitecture") |
25 |
| - ) |
| 23 | + return UnsafeMutableRawPointer(mutating: #dsohandle) |
| 24 | + }(), |
| 25 | + log: OSLog(subsystem: "com.apple.runtime-issues", category: "ComposableArchitecture") |
| 26 | + ) |
| 27 | + |
| 28 | + #else |
| 29 | + let rw = (dso: (), log: ()) |
| 30 | + |
| 31 | + enum OSLogType { |
| 32 | + case fault |
| 33 | + } |
| 34 | + |
| 35 | + func os_log(_ type: OSLogType, dso: Void, log: Void, _ message: String, _ args: CVarArg...) { |
| 36 | + print(String(format: message, arguments: args)) |
| 37 | + } |
| 38 | + #endif |
26 | 39 | #endif
|
0 commit comments