@@ -19,6 +19,41 @@ @interface FLEXArgumentInputStructView ()
19
19
20
20
@implementation FLEXArgumentInputStructView
21
21
22
+ static NSMutableDictionary <NSString *, NSArray <NSString *> *> *structFieldNameRegistrar = nil ;
23
+ + (void )initialize {
24
+ if (self == [FLEXArgumentInputStructView class ]) {
25
+ structFieldNameRegistrar = [NSMutableDictionary new ];
26
+ [self registerDefaultFieldNames ];
27
+ }
28
+ }
29
+
30
+ + (void )registerDefaultFieldNames {
31
+ NSDictionary *defaults = @{
32
+ @(@encode (CGRect )): @[@" CGPoint origin" , @" CGSize size" ],
33
+ @(@encode (CGPoint )): @[@" CGFloat x" , @" CGFloat y" ],
34
+ @(@encode (CGSize )): @[@" CGFloat width" , @" CGFloat height" ],
35
+ @(@encode (CGVector )): @[@" CGFloat dx" , @" CGFloat dy" ],
36
+ @(@encode (UIEdgeInsets)): @[@" CGFloat top" , @" CGFloat left" , @" CGFloat bottom" , @" CGFloat right" ],
37
+ @(@encode (UIOffset)): @[@" CGFloat horizontal" , @" CGFloat vertical" ],
38
+ @(@encode (NSRange )): @[@" NSUInteger location" , @" NSUInteger length" ],
39
+ @(@encode (CATransform3D)): @[@" CGFloat m11" , @" CGFloat m12" , @" CGFloat m13" , @" CGFloat m14" ,
40
+ @" CGFloat m21" , @" CGFloat m22" , @" CGFloat m23" , @" CGFloat m24" ,
41
+ @" CGFloat m31" , @" CGFloat m32" , @" CGFloat m33" , @" CGFloat m34" ,
42
+ @" CGFloat m41" , @" CGFloat m42" , @" CGFloat m43" , @" CGFloat m44" ],
43
+ @(@encode (CGAffineTransform )): @[@" CGFloat a" , @" CGFloat b" ,
44
+ @" CGFloat c" , @" CGFloat d" ,
45
+ @" CGFloat tx" , @" CGFloat ty" ],
46
+ };
47
+
48
+ [structFieldNameRegistrar addEntriesFromDictionary: defaults];
49
+
50
+ if (@available (iOS 11.0 , *)) {
51
+ structFieldNameRegistrar[@(@encode (NSDirectionalEdgeInsets ))] = @[
52
+ @" CGFloat top" , @" CGFloat leading" , @" CGFloat bottom" , @" CGFloat trailing"
53
+ ];
54
+ }
55
+ }
56
+
22
57
- (instancetype )initWithArgumentTypeEncoding : (const char *)typeEncoding {
23
58
self = [super initWithArgumentTypeEncoding: typeEncoding];
24
59
if (self) {
@@ -181,40 +216,13 @@ + (BOOL)supportsObjCType:(const char *)type withCurrentValue:(id)value {
181
216
return NO ;
182
217
}
183
218
219
+ + (void )registerFieldNames : (NSArray <NSString *> *)names forTypeEncoding : (NSString *)typeEncoding {
220
+ NSParameterAssert (typeEncoding); NSParameterAssert(names);
221
+ structFieldNameRegistrar[typeEncoding] = names;
222
+ }
223
+
184
224
+ (NSArray <NSString *> *)customFieldTitlesForTypeEncoding : (const char *)typeEncoding {
185
- NSArray <NSString *> *customTitles = nil ;
186
- if (strcmp (typeEncoding, @encode (CGRect )) == 0 ) {
187
- customTitles = @[@" CGPoint origin" , @" CGSize size" ];
188
- } else if (strcmp (typeEncoding, @encode (CGPoint )) == 0 ) {
189
- customTitles = @[@" CGFloat x" , @" CGFloat y" ];
190
- } else if (strcmp (typeEncoding, @encode (CGSize )) == 0 ) {
191
- customTitles = @[@" CGFloat width" , @" CGFloat height" ];
192
- } else if (strcmp (typeEncoding, @encode (CGVector )) == 0 ) {
193
- customTitles = @[@" CGFloat dx" , @" CGFloat dy" ];
194
- } else if (strcmp (typeEncoding, @encode (UIEdgeInsets)) == 0 ) {
195
- customTitles = @[@" CGFloat top" , @" CGFloat left" , @" CGFloat bottom" , @" CGFloat right" ];
196
- } else if (strcmp (typeEncoding, @encode (UIOffset)) == 0 ) {
197
- customTitles = @[@" CGFloat horizontal" , @" CGFloat vertical" ];
198
- } else if (strcmp (typeEncoding, @encode (NSRange )) == 0 ) {
199
- customTitles = @[@" NSUInteger location" , @" NSUInteger length" ];
200
- } else if (strcmp (typeEncoding, @encode (CATransform3D)) == 0 ) {
201
- customTitles = @[@" CGFloat m11" , @" CGFloat m12" , @" CGFloat m13" , @" CGFloat m14" ,
202
- @" CGFloat m21" , @" CGFloat m22" , @" CGFloat m23" , @" CGFloat m24" ,
203
- @" CGFloat m31" , @" CGFloat m32" , @" CGFloat m33" , @" CGFloat m34" ,
204
- @" CGFloat m41" , @" CGFloat m42" , @" CGFloat m43" , @" CGFloat m44" ];
205
- } else if (strcmp (typeEncoding, @encode (CGAffineTransform )) == 0 ) {
206
- customTitles = @[@" CGFloat a" , @" CGFloat b" ,
207
- @" CGFloat c" , @" CGFloat d" ,
208
- @" CGFloat tx" , @" CGFloat ty" ];
209
- } else {
210
- if (@available (iOS 11.0 , *)) {
211
- if (strcmp (typeEncoding, @encode (NSDirectionalEdgeInsets )) == 0 ) {
212
- customTitles = @[@" CGFloat top" , @" CGFloat leading" ,
213
- @" CGFloat bottom" , @" CGFloat trailing" ];
214
- }
215
- }
216
- }
217
- return customTitles;
225
+ return structFieldNameRegistrar[@(typeEncoding)];
218
226
}
219
227
220
228
@end
0 commit comments