diff --git a/Code/ObjectMapping/RKPropertyInspector.h b/Code/ObjectMapping/RKPropertyInspector.h index 581fc3cb..35cc13a6 100644 --- a/Code/ObjectMapping/RKPropertyInspector.h +++ b/Code/ObjectMapping/RKPropertyInspector.h @@ -1,5 +1,5 @@ // -// RKObjectPropertyInspector.h +// RKPropertyInspector.h // RestKit // // Created by Blake Watters on 3/4/10. @@ -22,26 +22,54 @@ @class NSEntityDescription; +/** + The `RKPropertyInspector` class provides an interface for introspecting the properties and attributes of classes using the reflection capabilities of the Objective-C runtime. Once inspected, the properties and types are cached. + */ @interface RKPropertyInspector : NSObject { @protected NSCache *_propertyNamesToTypesCache; } -+ (RKPropertyInspector *)sharedInspector; +///----------------------------------------------- +/// @name Retrieving the Shared Inspector Instance +///----------------------------------------------- /** - * Returns a dictionary of names and types for the properties of a given class + Returns the shared property inspector singleton instance. + + @return The shared `RKPropertyInspector` instance. + */ ++ (RKPropertyInspector *)sharedInspector; + +///------------------------------------------------------ +/// @name Retrieving the Properties and Types for a Class +///------------------------------------------------------ + +/** + Returns a dictionary of names and types for the properties of a given class. + + @param objectClass The class to retrieve the property name and types for. + @return A dictionary containing metadata about the properties of the given class, where the keys in the dictionary are the property names and the values are `Class` objects specifying the type of the property. */ - (NSDictionary *)propertyNamesAndTypesForClass:(Class)objectClass; /** - Returns the Class type of the specified property on the object class + Returns the `Class` object specifying the type of the property with given name on a class. + + @param propertyName The name of the property to retrieve the type of. + @param objectClass The class to retrieve the property from. + @return A `Class` object specifying the type of the requested property. */ - (Class)typeForProperty:(NSString *)propertyName ofClass:(Class)objectClass; +///------------------------------------------------------ +/// @name Retrieving the Properties and Types for a Class +///------------------------------------------------------ /** - Returns the name of a property when provided the name of a property obtained - via the property_getAttributes reflection API + Returns the name of a property when provided the name of a property obtained via the `property_getAttributes` reflection API. + + @param attributeString A string object encoding attribute information. + @return The class name for the property type encoded in the given attribute string or `@"NULL"` if the property does not have an object type (the declared property is for a primitive type). */ + (NSString *)propertyTypeFromAttributeString:(NSString *)attributeString; diff --git a/Code/ObjectMapping/RKPropertyInspector.m b/Code/ObjectMapping/RKPropertyInspector.m index 05473fe8..af8e56b2 100644 --- a/Code/ObjectMapping/RKPropertyInspector.m +++ b/Code/ObjectMapping/RKPropertyInspector.m @@ -26,15 +26,15 @@ #undef RKLogComponent #define RKLogComponent lcl_cRestKitObjectMapping -static RKPropertyInspector *sharedInspector = nil; - @implementation RKPropertyInspector + (RKPropertyInspector *)sharedInspector { - if (sharedInspector == nil) { + static RKPropertyInspector *sharedInspector = nil; + static dispatch_once_t onceToken; + dispatch_once(&onceToken, ^{ sharedInspector = [RKPropertyInspector new]; - } + }); return sharedInspector; }