12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 |
- //
- // FLEXRuntimeUtility.h
- // Flipboard
- //
- // Created by Ryan Olson on 6/8/14.
- // Copyright (c) 2020 FLEX Team. All rights reserved.
- //
- #import "FLEXRuntimeConstants.h"
- #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 \
- ]; \
- } \
- })
- /// 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__);
- @interface FLEXRuntimeUtility : NSObject
- // General Helpers
- + (BOOL)pointerIsValidObjcObject:(const void *)pointer;
- /// Unwraps raw pointers to objects stored in NSValue, and re-boxes C strings into NSStrings.
- + (id)potentiallyUnwrapBoxedPointer:(id)returnedObjectOrNil type:(const FLEXTypeEncoding *)returnType;
- /// Some fields have a name in their encoded string (e.g. \"width\"d)
- /// @return the offset to skip the field name, 0 if there is no name
- + (NSUInteger)fieldNameOffsetForTypeEncoding:(const FLEXTypeEncoding *)typeEncoding;
- /// Given name "foo" and type "int" this would return "int foo", but
- /// given name "foo" and type "T *" it would return "T *foo"
- + (NSString *)appendName:(NSString *)name toType:(NSString *)typeEncoding;
- /// @return The class hierarchy for the given object or class,
- /// from the current class to the root-most class.
- + (NSArray<Class> *)classHierarchyOfObject:(id)objectOrClass;
- /// Used to describe an object in brief within an explorer row
- + (NSString *)summaryForObject:(id)value;
- + (NSString *)safeClassNameForObject:(id)object;
- + (NSString *)safeDescriptionForObject:(id)object;
- + (NSString *)safeDebugDescriptionForObject:(id)object;
- + (BOOL)safeObject:(id)object isKindOfClass:(Class)cls;
- + (BOOL)safeObject:(id)object respondsToSelector:(SEL)sel;
- // Property Helpers
- + (BOOL)tryAddPropertyWithName:(const char *)name
- attributes:(NSDictionary<NSString *, NSString *> *)attributePairs
- toClass:(__unsafe_unretained Class)theClass;
- + (NSArray<NSString *> *)allPropertyAttributeKeys;
- // Method Helpers
- + (NSArray *)prettyArgumentComponentsForMethod:(Method)method;
- // Method Calling/Field Editing
- + (id)performSelector:(SEL)selector onObject:(id)object;
- + (id)performSelector:(SEL)selector
- onObject:(id)object
- withArguments:(NSArray *)arguments
- error:(NSError * __autoreleasing *)error;
- + (NSString *)editableJSONStringForObject:(id)object;
- + (id)objectValueFromEditableJSONString:(NSString *)string;
- + (NSValue *)valueForNumberWithObjCType:(const char *)typeEncoding fromInputString:(NSString *)inputString;
- + (void)enumerateTypesInStructEncoding:(const char *)structEncoding
- usingBlock:(void (^)(NSString *structName,
- const char *fieldTypeEncoding,
- NSString *prettyTypeEncoding,
- NSUInteger fieldIndex,
- NSUInteger fieldOffset))typeBlock;
- + (NSValue *)valueForPrimitivePointer:(void *)pointer objCType:(const char *)type;
- #pragma mark - Metadata Helpers
- + (NSString *)readableTypeForEncoding:(NSString *)encodingString;
- @end
|