FLEXPropertyAttributes.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. //
  2. // FLEXPropertyAttributes.h
  3. // FLEX
  4. //
  5. // Derived from MirrorKit.
  6. // Created by Tanner on 7/5/15.
  7. // Copyright (c) 2015 Tanner Bennett. All rights reserved.
  8. //
  9. #import <Foundation/Foundation.h>
  10. #import <objc/runtime.h>
  11. NS_ASSUME_NONNULL_BEGIN
  12. #pragma mark FLEXPropertyAttributes
  13. /// See \e FLEXRuntimeUtilitiy.h for valid string tokens.
  14. /// See this link on how to construct a proper attributes string:
  15. /// https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/ObjCRuntimeGuide/Articles/ocrtPropertyIntrospection.html
  16. @interface FLEXPropertyAttributes : NSObject <NSCopying, NSMutableCopying> {
  17. // These are necessary for the mutable subclass to function
  18. @protected
  19. NSUInteger _count;
  20. NSString *_string, *_backingIvar, *_typeEncoding, *_oldTypeEncoding, *_fullDeclaration;
  21. NSDictionary *_dictionary;
  22. objc_property_attribute_t *_list;
  23. SEL _customGetter, _customSetter;
  24. BOOL _isReadOnly, _isCopy, _isRetained, _isNonatomic, _isDynamic, _isWeak, _isGarbageCollectable;
  25. }
  26. + (instancetype)attributesForProperty:(objc_property_t)property;
  27. /// @warning Raises an exception if \e attributes is invalid, \c nil, or contains unsupported keys.
  28. + (instancetype)attributesFromDictionary:(NSDictionary *)attributes;
  29. /// Copies the attributes list to a buffer you must \c free() yourself.
  30. /// Use \c list instead if you do not need more control over the lifetime of the list.
  31. /// @param attributesCountOut the number of attributes is returned in this parameter.
  32. - (objc_property_attribute_t *)copyAttributesList:(nullable unsigned int *)attributesCountOut;
  33. /// The number of property attributes.
  34. @property (nonatomic, readonly) NSUInteger count;
  35. /// For use with \c class_replaceProperty and the like.
  36. @property (nonatomic, readonly) objc_property_attribute_t *list;
  37. /// The string value of the property attributes.
  38. @property (nonatomic, readonly) NSString *string;
  39. /// A human-readable version of the property attributes.
  40. @property (nonatomic, readonly) NSString *fullDeclaration;
  41. /// A dictionary of the property attributes.
  42. /// Values are either a string or \c @YES. Boolean attributes
  43. /// which are false will not be present in the dictionary.
  44. @property (nonatomic, readonly) NSDictionary *dictionary;
  45. /// The name of the instance variable backing the property.
  46. @property (nonatomic, readonly, nullable) NSString *backingIvar;
  47. /// The type encoding of the property.
  48. @property (nonatomic, readonly, nullable) NSString *typeEncoding;
  49. /// The \e old type encoding of the property.
  50. @property (nonatomic, readonly, nullable) NSString *oldTypeEncoding;
  51. /// The property's custom getter, if any.
  52. @property (nonatomic, readonly, nullable) SEL customGetter;
  53. /// The property's custom setter, if any.
  54. @property (nonatomic, readonly, nullable) SEL customSetter;
  55. @property (nonatomic, readonly) BOOL isReadOnly;
  56. @property (nonatomic, readonly) BOOL isCopy;
  57. @property (nonatomic, readonly) BOOL isRetained;
  58. @property (nonatomic, readonly) BOOL isNonatomic;
  59. @property (nonatomic, readonly) BOOL isDynamic;
  60. @property (nonatomic, readonly) BOOL isWeak;
  61. @property (nonatomic, readonly) BOOL isGarbageCollectable;
  62. @end
  63. #pragma mark FLEXPropertyAttributes
  64. @interface FLEXMutablePropertyAttributes : FLEXPropertyAttributes
  65. /// Creates and returns an empty property attributes object.
  66. + (instancetype)attributes;
  67. /// The name of the instance variable backing the property.
  68. @property (nonatomic, nullable) NSString *backingIvar;
  69. /// The type encoding of the property.
  70. @property (nonatomic, nullable) NSString *typeEncoding;
  71. /// The \e old type encoding of the property.
  72. @property (nonatomic, nullable) NSString *oldTypeEncoding;
  73. /// The property's custom getter, if any.
  74. @property (nonatomic, nullable) SEL customGetter;
  75. /// The property's custom setter, if any.
  76. @property (nonatomic, nullable) SEL customSetter;
  77. @property (nonatomic) BOOL isReadOnly;
  78. @property (nonatomic) BOOL isCopy;
  79. @property (nonatomic) BOOL isRetained;
  80. @property (nonatomic) BOOL isNonatomic;
  81. @property (nonatomic) BOOL isDynamic;
  82. @property (nonatomic) BOOL isWeak;
  83. @property (nonatomic) BOOL isGarbageCollectable;
  84. /// A more convenient method of setting the \c typeEncoding property.
  85. /// @discussion This will not work for complex types like structs and primitive pointers.
  86. - (void)setTypeEncodingChar:(char)type;
  87. @end
  88. NS_ASSUME_NONNULL_END