Either I do something wrong or it does not work. The crash always says expected in: .../SwiftUI.framework/SwiftUI
. Wouldn't that require the patch to exist inside the framework itself instead of my own code?
Maybe you can try to patch it on the SwiftUI side. (Modifying SwiftUI.interfaceface file in the SDK path)
Found a great article explaining Apple's magic on linking. The alike trick in ld64 may also apply here for the OP's issue.
TL;DR
- Appleās linker,
ld64
, recognises specially named symbols which change its linking
behaviour.- Those magic symbols can customise behaviour on a per-deployment target basis.
- The Swift runtime leverages those magic symbols to change its install name.
- āasm labelsā are used to define such magic symbols which start without a underscore.
Thank you for still thinking about it, or at least remembering it. :D The issue was really critical and since I couldn't find a working solution I've implemented a different approach from starch to solve the task. On iOS 15 we now use a potentially no so safe nor 100% stable introspection solution. If it breaks, then it breaks. On iOS 16 and above we're using a UIKit - SwiftUI sandwich using a hosted UICollectionView + UIHostingConfiguration. It works great, but it was tricky to nail it down and solve the new caveats.
Another context to add here:
The magic which Apple is using seems to be @_originallyDefinedIn
.
You can find the detail in ${SDK_ROOT}/usr/lib/swift/CoreFoundation.swiftmodule/arm64e-apple-ios-macabi.swiftinterface
eg.
@available(macOS 10.0, macCatalyst 13.0, iOS 2.0, watchOS 1.0, tvOS 9.0, *)
@_originallyDefinedIn(module: "CoreGraphics", macOS 10.0)
@_originallyDefinedIn(module: "CoreGraphics", macCatalyst 13.0)
@_originallyDefinedIn(module: "CoreGraphics", iOS 2.0)
@_originallyDefinedIn(module: "CoreGraphics", watchOS 1.0)
@_originallyDefinedIn(module: "CoreGraphics", tvOS 9.0)
@frozen public struct CGFloat {
public typealias NativeType = Swift.Double
@_transparent public init() {
self.native = 0.0
}
@_transparent public init(_ value: Swift.Float) {
self.native = NativeType(value)
}
@_transparent public init(_ value: Swift.Double) {
self.native = NativeType(value)
}
@_transparent public init(_ value: CoreFoundation.CGFloat) {
self.native = value.native
}
public var native: CoreFoundation.CGFloat.NativeType
}
@available(macOS 10.0, macCatalyst 13.0, iOS 2.0, watchOS 1.0, tvOS 9.0, *)
@_originallyDefinedIn(module: "CoreGraphics", macOS 10.0)
@_originallyDefinedIn(module: "CoreGraphics", macCatalyst 13.0)
@_originallyDefinedIn(module: "CoreGraphics", iOS 2.0)
@_originallyDefinedIn(module: "CoreGraphics", watchOS 1.0)
@_originallyDefinedIn(module: "CoreGraphics", tvOS 9.0)
extension CoreFoundation.CGFloat : Swift.SignedNumeric {
...
}