Skip to content

Commit ba9c626

Browse files
authored
Improved way to get SwiftUI image handle (#945)
* Improved way to get SwiftUI image handle * Use #dsohandle instead of fatalerror * Search /SwiftUI instead and use dyld image header pointer instead of convert it Previous approch will crash on mac platform but ok with iOS simulator
1 parent 43b2ae6 commit ba9c626

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

Sources/ComposableArchitecture/Internal/RuntimeWarnings.swift

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,18 @@
88
// Feedback filed: https://gist.github.com/stephencelis/a8d06383ed6ccde3e5ef5d1b3ad52bbc
99
let rw = (
1010
dso: { () -> UnsafeMutableRawPointer in
11-
var info = Dl_info()
12-
dladdr(dlsym(dlopen(nil, RTLD_LAZY), "LocalizedString"), &info)
13-
return info.dli_fbase
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))
18+
}
19+
}
20+
}
21+
}
22+
return UnsafeMutableRawPointer(mutating: #dsohandle)
1423
}(),
1524
log: OSLog(subsystem: "com.apple.runtime-issues", category: "ComposableArchitecture")
1625
)

0 commit comments

Comments
 (0)