|
|
1 месяц назад | |
|---|---|---|
| .. | ||
| Overlay | 1 месяц назад | |
| Shims | 1 месяц назад | |
| Util | 1 месяц назад | |
| OpenSwiftUIBase.h | 1 месяц назад | |
| OpenSwiftUITargetConditionals.h | 1 месяц назад | |
| README.md | 1 месяц назад | |
| module.modulemap | 1 месяц назад | |
For private Darwin ObjectiveC API, we use shims wrapped to replace the direct private API call to avoid breaking change.
Below is an example of how to shim a private API call.
@interface UIApplication (OpenSwiftUI_SPI)
- (void)_performBlockAfterCATransactionCommits_openswiftui_safe_wrapper:(void (^)(void))block OPENSWIFTUI_SWIFT_NAME(_performBlockAfterCATransactionCommits(_:));
@end
@implementation UIApplication (OpenSwiftUI_SPI)
- (void)_performBlockAfterCATransactionCommits_openswiftui_safe_wrapper:(void (^)(void))block {
typedef void (*Func)(UIApplication *, SEL, void (^)(void));
SEL selector = NSSelectorFromString(@"_performBlockAfterCATransactionCommits:");
Func func = nil;
if ([self respondsToSelector:selector]) {
IMP impl = class_getMethodImplementation([self class], selector);
func = (Func)impl;
}
if (func != nil) {
func(self, selector, block);
}
}
@end
extension UIApplication {
func _performBlockAfterCATransactionCommits(_ block: @escaping (Int) -> Void) {
typealias Function = @convention(c) (UIApplication, Selector, @escaping (Int) -> Void) -> Void
let selector = Selector(("_performBlockAfterCATransactionCommits:"))
guard responds(to: selector),
let implementation = class_getMethodImplementation(UIApplication.self, selector)
else {
return
}
let function = unsafeBitCast(implementation, to: Function.self)
return function(self, selector, block)
}
}
TODO: