Просмотр исходного кода

Move UIView(Controller) runtime property additions

… to FLEXShortcutsFactory+Defaults.m
Tanner Bennett лет назад: 6
Родитель
Сommit
d23f01dd87

+ 27 - 4
Classes/ObjectExplorers/Sections/Shortcuts/FLEXShortcutsFactory+Defaults.m

@@ -8,16 +8,36 @@
 
 #import "FLEXShortcutsFactory+Defaults.h"
 #import "FLEXShortcut.h"
-#import <objc/runtime.h>
-
-// Don't load pre-registered shortcuts in a test environment
-#define FLEX_EXIT_IF_TESTING() if (NSClassFromString(@"XCTest")) return;
+#import "FLEXRuntimeUtility.h"
+#import "NSObject+Reflection.h"
 
 #pragma mark - Views
 
 @implementation FLEXShortcutsFactory (Views)
 
 + (void)load { FLEX_EXIT_IF_TESTING()
+    // A quirk of UIView and some other classes: a lot of the `@property`s are
+    // not actually properties from the perspective of the runtime.
+    //
+    // We add these properties to the class at runtime if they haven't been added yet.
+    // This way, we can use our property editor to access and change them.
+    // The property attributes match the declared attributes in their headers.
+
+    // UIView, public
+    Class UIView_ = UIView.class;
+    FLEXRuntimeUtilityTryAddNonatomicProperty(2, frame, UIView_, CGRect);
+    FLEXRuntimeUtilityTryAddNonatomicProperty(2, alpha, UIView_, CGFloat);
+    FLEXRuntimeUtilityTryAddNonatomicProperty(2, clipsToBounds, UIView_, BOOL);
+    FLEXRuntimeUtilityTryAddNonatomicProperty(2, opaque, UIView_, BOOL, PropertyKeyGetter(isOpaque));
+    FLEXRuntimeUtilityTryAddNonatomicProperty(2, hidden, UIView_, BOOL, PropertyKeyGetter(isHidden));
+    FLEXRuntimeUtilityTryAddObjectProperty(2, backgroundColor, UIView_, UIColor, PropertyKey(Copy));
+    FLEXRuntimeUtilityTryAddObjectProperty(6, constraints, UIView_, NSArray, PropertyKey(ReadOnly));
+    FLEXRuntimeUtilityTryAddObjectProperty(2, subviews, UIView_, NSArray, PropertyKey(ReadOnly));
+    FLEXRuntimeUtilityTryAddObjectProperty(2, superview, UIView_, UIView, PropertyKey(ReadOnly));
+
+    // UIButton, private
+    FLEXRuntimeUtilityTryAddObjectProperty(2, font, UIButton.class, UIFont, PropertyKey(ReadOnly));
+    
     // Only available since iOS 3.2, but we never supported iOS 3, so who cares
     NSArray *ivars = @[@"_gestureRecognizers"];
     NSArray *methods = @[@"sizeToFit", @"setNeedsLayout", @"removeFromSuperview"];
@@ -77,6 +97,9 @@
 @implementation FLEXShortcutsFactory (ViewControllers)
 
 + (void)load { FLEX_EXIT_IF_TESTING()
+    // toolbarItems is not really a property, make it one 
+    FLEXRuntimeUtilityTryAddObjectProperty(3, toolbarItems, UIViewController.class, NSArray);
+    
     // UIViewController
     self.append
         .properties(@[

+ 0 - 55
Classes/ObjectExplorers/Sections/Shortcuts/FLEXViewShortcuts.m

@@ -84,59 +84,4 @@
     ]];
 }
 
-
-#pragma mark - Runtime Adjustment
-
-#define PropertyKey(suffix) kFLEXPropertyAttributeKey##suffix : @""
-#define PropertyKeyGetter(getter) kFLEXPropertyAttributeKeyCustomGetter : NSStringFromSelector(@selector(getter))
-#define PropertyKeySetter(setter) kFLEXPropertyAttributeKeyCustomSetter : NSStringFromSelector(@selector(setter))
-
-/// Takes: min iOS version, property name, target class, property type, and a list of attributes
-#define FLEXRuntimeUtilityTryAddProperty(iOS_atLeast, name, cls, type, ...) ({ \
-    if (@available(iOS iOS_atLeast, *)) { \
-        NSMutableDictionary *attrs = [NSMutableDictionary dictionaryWithDictionary:@{ \
-            kFLEXPropertyAttributeKeyTypeEncoding : @(type), \
-            __VA_ARGS__ \
-        }]; \
-        [FLEXRuntimeUtility \
-            tryAddPropertyWithName:#name \
-            attributes:attrs \
-            toClass:[cls class] \
-        ]; \
-    } \
-})
-
-/// Takes: min iOS version, property name, target class, property type, and a list of attributes
-#define FLEXRuntimeUtilityTryAddNonatomicProperty(iOS_atLeast, name, cls, type, ...) \
-    FLEXRuntimeUtilityTryAddProperty(iOS_atLeast, name, cls, @encode(type), PropertyKey(NonAtomic), __VA_ARGS__);
-/// Takes: min iOS version, property name, target class, property type (class name), and a list of attributes
-#define FLEXRuntimeUtilityTryAddObjectProperty(iOS_atLeast, name, cls, type, ...) \
-    FLEXRuntimeUtilityTryAddProperty(iOS_atLeast, name, cls, FLEXEncodeClass(type), PropertyKey(NonAtomic), __VA_ARGS__);
-
-+ (void)load {
-    // A quirk of UIView and some other classes: a lot of the `@property`s are
-    // not actually properties from the perspective of the runtime.
-    //
-    // We add these properties to the class at runtime if they haven't been added yet.
-    // This way, we can use our property editor to access and change them.
-    // The property attributes match the declared attributes in their headers.
-
-    // UIView, public
-    FLEXRuntimeUtilityTryAddNonatomicProperty(2, frame, UIView, CGRect);
-    FLEXRuntimeUtilityTryAddNonatomicProperty(2, alpha, UIView, CGFloat);
-    FLEXRuntimeUtilityTryAddNonatomicProperty(2, clipsToBounds, UIView, BOOL);
-    FLEXRuntimeUtilityTryAddNonatomicProperty(2, opaque, UIView, BOOL, PropertyKeyGetter(isOpaque));
-    FLEXRuntimeUtilityTryAddNonatomicProperty(2, hidden, UIView, BOOL, PropertyKeyGetter(isHidden));
-    FLEXRuntimeUtilityTryAddObjectProperty(2, backgroundColor, UIView, UIColor, PropertyKey(Copy));
-    FLEXRuntimeUtilityTryAddObjectProperty(6, constraints, UIView, NSArray, PropertyKey(ReadOnly));
-    FLEXRuntimeUtilityTryAddObjectProperty(2, subviews, UIView, NSArray, PropertyKey(ReadOnly));
-    FLEXRuntimeUtilityTryAddObjectProperty(2, superview, UIView, UIView, PropertyKey(ReadOnly));
-
-    // UIButton, private
-    FLEXRuntimeUtilityTryAddObjectProperty(2, font, UIButton, UIFont, PropertyKey(ReadOnly));
-    
-    // UIViewController, public
-    FLEXRuntimeUtilityTryAddObjectProperty(3, toolbarItems, UIViewController, NSArray);
-}
-
 @end