Taking Notes

cause i'll forget

Objective-C Declared Property Introspection

Here’s a fun little NSObject category that allows you to pop out an object’s declared properties into a dictionary keyed by the property names.

NSObject+PropertyDictionary

The values in the dictionary are ESDeclaredPropertyAttributes objects that should give you most of the data you’d want for most kinds of properties most of the time. (A comprehensive object that gives you all the possible data stored into a declared properties would be a complicated kitchen sink and only marginally more usable)

typedef enum {
    AssignStorage, // assign is the default declared property setter type
    StrongStorage,
    CopyStorage,
    ReadOnlyStorage
} PropertyStorageMethod;

// Not going to try to support
// enum, struct, union, int *, void *, long, short, signed, unsigned, etc
typedef enum
{
    IDType,
    ObjectType,
    CharType,
    DoubleType,
    FloatType,
    IntType,
    UnsupportedType
} PropertyStorageType;

@interface ESDeclaredPropertyAttributes : NSObject

@property (strong, nonatomic) NSString *classString;
@property (strong, nonatomic) NSString *name;
@property (nonatomic) PropertyStorageType storageType;
@property (nonatomic) SEL getter;
@property (nonatomic) SEL setter;
@property (nonatomic) PropertyStorageMethod storageMethod;
@property (nonatomic) BOOL readOnly;
@property (nonatomic) BOOL nonatomic;
@property (nonatomic) BOOL dynamic;

@end