|
5 | 5 | // Status: WIP
|
6 | 6 |
|
7 | 7 | #import "UIKit_Private.h"
|
| 8 | +#import "../OpenSwiftUIShims.h" |
8 | 9 |
|
9 | 10 | #if __has_include(<UIKit/UIKit.h>)
|
10 | 11 |
|
11 | 12 | #import <objc/runtime.h>
|
12 | 13 |
|
13 | 14 | @implementation UIApplication (OpenSwiftUI_SPI)
|
14 | 15 | - (void)_performBlockAfterCATransactionCommits_openswiftui_safe_wrapper:(void (^)(void))block {
|
15 |
| - typedef void (*Func)(UIApplication *, SEL, void (^)(void)); |
16 |
| - SEL selector = NSSelectorFromString(@"_performBlockAfterCATransactionCommits:"); |
17 |
| - Func func = nil; |
18 |
| - if ([self respondsToSelector:selector]) { |
19 |
| - IMP impl = class_getMethodImplementation([self class], selector); |
20 |
| - func = (Func)impl; |
21 |
| - } |
22 |
| - if (func != nil) { |
23 |
| - func(self, selector, block); |
24 |
| - } |
| 16 | + OPENSWIFTUI_SAFE_WRAPPER_IMP(void, @"_performBlockAfterCATransactionCommits:", block(),void (^)(void)); |
| 17 | + func(self, selector, block); |
25 | 18 | }
|
26 | 19 |
|
27 | 20 | - (void)startedTest_openswiftui_safe_wrapper:(NSString *)name {
|
28 |
| - typedef void (*Func)(UIApplication *, SEL, NSString *); |
29 |
| - SEL selector = NSSelectorFromString(@"startedTest:"); |
30 |
| - Func func = nil; |
31 |
| - if ([self respondsToSelector:selector]) { |
32 |
| - IMP impl = class_getMethodImplementation([self class], selector); |
33 |
| - func = (Func)impl; |
34 |
| - } |
35 |
| - if (func != nil) { |
36 |
| - func(self, selector, name); |
37 |
| - } |
| 21 | + OPENSWIFTUI_SAFE_WRAPPER_IMP(void, @"startedTest:", , NSString *); |
| 22 | + func(self, selector, name); |
38 | 23 | }
|
39 | 24 |
|
40 | 25 | - (void)finishedTest_openswiftui_safe_wrapper:(NSString *)name {
|
41 |
| - typedef void (*Func)(UIApplication *, SEL, NSString *); |
42 |
| - SEL selector = NSSelectorFromString(@"finishedTest:"); |
43 |
| - Func func = nil; |
44 |
| - if ([self respondsToSelector:selector]) { |
45 |
| - IMP impl = class_getMethodImplementation([self class], selector); |
46 |
| - func = (Func)impl; |
47 |
| - } |
48 |
| - if (func != nil) { |
49 |
| - func(self, selector, name); |
50 |
| - } |
| 26 | + OPENSWIFTUI_SAFE_WRAPPER_IMP(void, @"finishedTest:", , NSString *); |
| 27 | + func(self, selector, name); |
51 | 28 | }
|
52 | 29 |
|
53 | 30 | - (void)failedTest_openswiftui_safe_wrapper:(NSString *)name withFailure:(NSError *)failure {
|
54 |
| - typedef void (*Func)(UIApplication *, SEL, NSString *, NSError *); |
55 |
| - SEL selector = NSSelectorFromString(@"failedTest:withFailure:"); |
56 |
| - Func func = nil; |
57 |
| - if ([self respondsToSelector:selector]) { |
58 |
| - IMP impl = class_getMethodImplementation([self class], selector); |
59 |
| - func = (Func)impl; |
60 |
| - } |
61 |
| - if (func != nil) { |
62 |
| - func(self, selector, name, failure); |
63 |
| - } |
| 31 | + OPENSWIFTUI_SAFE_WRAPPER_IMP(void, @"failedTest:withFailure:", , NSString *, NSError *); |
| 32 | + func(self, selector, name, failure); |
64 | 33 | }
|
65 | 34 |
|
66 | 35 | - (NSString *)_launchTestName_openswiftui_safe_wrapper {
|
67 |
| - typedef NSString* (*Func)(UIApplication *, SEL); |
68 |
| - SEL selector = NSSelectorFromString(@"_launchTestName"); |
69 |
| - Func func = nil; |
70 |
| - if ([self respondsToSelector:selector]) { |
71 |
| - IMP impl = class_getMethodImplementation([self class], selector); |
72 |
| - func = (Func)impl; |
73 |
| - } |
74 |
| - if (func != nil) { |
75 |
| - return func(self, selector); |
76 |
| - } |
77 |
| - return nil; |
| 36 | + OPENSWIFTUI_SAFE_WRAPPER_IMP(NSString *, @"_launchTestName", nil); |
| 37 | + return func(self, selector); |
78 | 38 | }
|
79 | 39 | @end
|
80 | 40 |
|
81 | 41 | @implementation UIView (OpenSwiftUI_SPI)
|
82 | 42 | - (BOOL)_shouldAnimatePropertyWithKey_openswiftui_safe_wrapper:(NSString *)key {
|
83 |
| - typedef BOOL (*Func)(UIView *, SEL, NSString *); |
84 |
| - SEL selector = NSSelectorFromString(@"_shouldAnimatePropertyWithKey:"); |
85 |
| - Func func = nil; |
86 |
| - if ([self respondsToSelector:selector]) { |
87 |
| - IMP impl = class_getMethodImplementation([self class], selector); |
88 |
| - func = (Func)impl; |
89 |
| - } |
90 |
| - if (func != nil) { |
91 |
| - return func(self, selector, key); |
92 |
| - } |
93 |
| - return NO; |
| 43 | + OPENSWIFTUI_SAFE_WRAPPER_IMP(BOOL, @"_shouldAnimatePropertyWithKey:", NO, NSString *); |
| 44 | + return func(self, selector, key); |
94 | 45 | }
|
95 | 46 | @end
|
96 | 47 |
|
97 | 48 | @implementation UIViewController (OpenSwiftUI_SPI)
|
98 | 49 | - (BOOL)_canShowWhileLocked_openswiftui_safe_wrapper {
|
99 |
| - typedef BOOL (*Func)(UIViewController *, SEL); |
100 |
| - SEL selector = NSSelectorFromString(@"_canShowWhileLocked"); |
101 |
| - Func func = nil; |
102 |
| - if ([self respondsToSelector:selector]) { |
103 |
| - IMP impl = class_getMethodImplementation([self class], selector); |
104 |
| - func = (Func)impl; |
105 |
| - } |
106 |
| - if (func != nil) { |
107 |
| - return func(self, selector); |
108 |
| - } |
109 |
| - return NO; |
| 50 | + OPENSWIFTUI_SAFE_WRAPPER_IMP(BOOL, @"_canShowWhileLocked", NO); |
| 51 | + return func(self, selector); |
110 | 52 | }
|
111 | 53 | @end
|
112 | 54 |
|
|
0 commit comments