Cleaning up some TODO's and such

This commit is contained in:
Blake Watters
2011-02-13 02:59:37 -05:00
parent 3467ac5d49
commit 0ea0a9b6d9
8 changed files with 35 additions and 29 deletions

View File

@@ -26,7 +26,7 @@ static NSString* const kRKManagedObjectContextKey = @"RKManagedObjectContext";
@synthesize managedObjectCache = _managedObjectCache;
- (id)initWithStoreFilename:(NSString*)storeFilename {
if (self = [self init]) {
if ((self = [self init])) {
_storeFilename = [storeFilename retain];
_managedObjectModel = [[NSManagedObjectModel mergedModelFromBundles:nil] retain];
[self createPersistentStoreCoordinator];

View File

@@ -8,11 +8,20 @@
#import "../ObjectMapping/ObjectMapping.h"
// TODO: This class needs an API scrubbing
/**
* The object seeder provides support for creating a pre-filled Core Data
* database suitable for shipping with your application at App Store submission
* time.
*/
@interface RKObjectSeeder : NSObject {
RKObjectManager* _manager;
}
/**
* Returns a new auto-released object manager
*/
+ (RKObjectSeeder*)seederWithObjectManager:(RKObjectManager*)manager;
/**
* Initialize a new object seeder
*/

View File

@@ -11,8 +11,12 @@
@implementation RKObjectSeeder
+ (RKObjectSeeder*)seederWithObjectManager:(RKObjectManager*)manager {
return [[[self alloc] initWithObjectManager:manager] autorelease];
}
- (id)initWithObjectManager:(RKObjectManager*)manager {
if (self = [self init]) {
if ((self = [self init])) {
_manager = [manager retain];
}

View File

@@ -59,7 +59,6 @@ typedef enum RKRequestMethod {
/**
* A serializable collection of parameters sent as the HTTP Body of the request
*/
// TODO: Should I be copy?
@property(nonatomic, retain) NSObject<RKRequestSerializable>* params;
/**

View File

@@ -13,7 +13,7 @@
@implementation RKDynamicRouter
- (id)init {
if (self = [super init]) {
if ((self = [super init])) {
_routes = [[NSMutableDictionary alloc] init];
}
@@ -40,7 +40,6 @@
[classRoutes setValue:resourcePath forKey:methodName];
}
// TODO: Should be RKStringFromRequestMethod and RKRequestMethodFromString
- (NSString*)HTTPVerbForMethod:(RKRequestMethod)method {
switch (method) {
case RKRequestMethodGET:
@@ -80,11 +79,11 @@
NSDictionary* classRoutes = [_routes objectForKey:className];
NSString* resourcePath = nil;
if (resourcePath = [classRoutes objectForKey:methodName]) {
if ((resourcePath = [classRoutes objectForKey:methodName])) {
return RKMakePathWithObject(resourcePath, object);
}
if (resourcePath = [classRoutes objectForKey:@"ANY"]) {
if ((resourcePath = [classRoutes objectForKey:@"ANY"])) {
return RKMakePathWithObject(resourcePath, object);
}

View File

@@ -14,6 +14,7 @@
/**
* Define the object mapping formats
*/
// TODO: Replace this with MIME Type -> Parser registration
typedef enum {
RKMappingFormatXML = 0,
RKMappingFormatJSON
@@ -128,7 +129,7 @@ typedef enum {
* Sets the properties and relationships serialized in the dictionary into the model instance
* provided
*/
- (void)mapObject:(id)model fromDictionary:(NSDictionary*)dictionary;
- (void)mapObject:(NSObject<RKObjectMappable>*)object fromDictionary:(NSDictionary*)dictionary;
/**
* Returns mapped model(s) from the data serialized in the dictionary into the model instance
@@ -149,20 +150,17 @@ typedef enum {
* Map the objects in a given payload string to a particular object class, optionally filtering
* the parsed result set via a keyPath before mapping the results.
*/
- (id)mapFromString:(NSString *)string toClass:(Class)class keyPath:(NSString*)keyPath;
- (NSObject<RKObjectMappable>*)mapFromString:(NSString *)string toClass:(Class<RKObjectMappable>)class keyPath:(NSString*)keyPath;
/**
* Map an array of object dictionary representations to instances of a particular
* object class
*/
- (NSArray*)mapObjectsFromArrayOfDictionaries:(NSArray*)array toClass:(Class)class;
- (NSArray*)mapObjectsFromArrayOfDictionaries:(NSArray*)array toClass:(Class<RKObjectMappable>)class;
/**
* Parse a string using the appropriate parser and return the results
*/
- (id)parseString:(NSString*)string;
///////////////////////////////////////////////////////////////////////////////
// Sub-classing Hooks
@end

View File

@@ -125,7 +125,7 @@ static const NSString* kRKModelMapperMappingFormatParserKey = @"RKMappingFormatP
return error;
}
- (id)mapFromString:(NSString*)string toClass:(Class)class keyPath:(NSString*)keyPath {
- (id)mapFromString:(NSString*)string toClass:(Class<RKObjectMappable>)class keyPath:(NSString*)keyPath {
id object = [self parseString:string];
if (keyPath) {
object = [object valueForKeyPath:keyPath];
@@ -152,7 +152,7 @@ static const NSString* kRKModelMapperMappingFormatParserKey = @"RKMappingFormatP
return [self mapFromString:string toClass:nil keyPath:nil];
}
- (void)mapObject:(id)model fromString:(NSString*)string {
- (void)mapObject:(NSObject<RKObjectMappable>*)model fromString:(NSString*)string {
id object = [self parseString:string];
if ([object isKindOfClass:[NSDictionary class]]) {
[self mapObject:model fromDictionary:object];
@@ -168,8 +168,7 @@ static const NSString* kRKModelMapperMappingFormatParserKey = @"RKMappingFormatP
///////////////////////////////////////////////////////////////////////////////
// Mapping from objects
// TODO: Should accept RKObjectMappable instead of id...
- (void)mapObject:(id)model fromDictionary:(NSDictionary*)dictionary {
- (void)mapObject:(NSObject<RKObjectMappable>*)model fromDictionary:(NSDictionary*)dictionary {
Class class = [model class];
NSArray* elementNames = [_elementToClassMappings allKeysForObject:class];
@@ -194,7 +193,7 @@ static const NSString* kRKModelMapperMappingFormatParserKey = @"RKMappingFormatP
}
// TODO: Can I make this support keyPath??
- (id)mapObjectFromDictionary:(NSDictionary*)dictionary {
- (NSObject<RKObjectMappable>*)mapObjectFromDictionary:(NSDictionary*)dictionary {
NSString* elementName = [[dictionary allKeys] objectAtIndex:0];
Class class = [_elementToClassMappings objectForKey:elementName];
NSDictionary* elements = [dictionary objectForKey:elementName];
@@ -221,7 +220,7 @@ static const NSString* kRKModelMapperMappingFormatParserKey = @"RKMappingFormatP
return (NSArray*)objects;
}
- (NSArray*)mapObjectsFromArrayOfDictionaries:(NSArray*)array toClass:(Class)class {
- (NSArray*)mapObjectsFromArrayOfDictionaries:(NSArray*)array toClass:(Class<RKObjectMappable>)class {
NSMutableArray* objects = [NSMutableArray array];
for (NSDictionary* dictionary in array) {
if (![dictionary isKindOfClass:[NSNull class]]) {
@@ -248,7 +247,7 @@ static const NSString* kRKModelMapperMappingFormatParserKey = @"RKMappingFormatP
// Persistent Instance Finders
// TODO: This version does not update properties. Should probably be realigned.
- (id)findOrCreateInstanceOfModelClass:(Class)class fromElements:(NSDictionary*)elements {
- (NSObject<RKObjectMappable>*)findOrCreateInstanceOfModelClass:(Class)class fromElements:(NSDictionary*)elements {
id object = nil;
Class managedObjectClass = NSClassFromString(@"RKManagedObject");
if (managedObjectClass && [class isSubclassOfClass:managedObjectClass]) {
@@ -270,7 +269,7 @@ static const NSString* kRKModelMapperMappingFormatParserKey = @"RKMappingFormatP
return object;
}
- (id)createOrUpdateInstanceOfModelClass:(Class)class fromElements:(NSDictionary*)elements {
- (NSObject<RKObjectMappable>*)createOrUpdateInstanceOfModelClass:(Class<RKObjectMappable>)class fromElements:(NSDictionary*)elements {
id model = [self findOrCreateInstanceOfModelClass:class fromElements:elements];
[self updateModel:model fromElements:elements];
return model;
@@ -279,7 +278,7 @@ static const NSString* kRKModelMapperMappingFormatParserKey = @"RKMappingFormatP
///////////////////////////////////////////////////////////////////////////////
// Property & Relationship Manipulation
- (void)updateModel:(id)model ifNewPropertyValue:(id)propertyValue forPropertyNamed:(NSString*)propertyName {
- (void)updateModel:(NSObject<RKObjectMappable>*)model ifNewPropertyValue:(id)propertyValue forPropertyNamed:(NSString*)propertyName {
id currentValue = [model valueForKey:propertyName];
if (nil == currentValue && nil == propertyValue) {
// Don't set the property, both are nil
@@ -317,7 +316,7 @@ static const NSString* kRKModelMapperMappingFormatParserKey = @"RKMappingFormatP
}
}
- (void)setPropertiesOfModel:(id)model fromElements:(NSDictionary*)elements {
- (void)setPropertiesOfModel:(NSObject<RKObjectMappable>*)model fromElements:(NSDictionary*)elements {
NSDictionary* elementToPropertyMappings = [self elementToPropertyMappingsForModel:model];
for (NSString* elementKeyPath in elementToPropertyMappings) {
id elementValue = nil;
@@ -353,7 +352,7 @@ static const NSString* kRKModelMapperMappingFormatParserKey = @"RKMappingFormatP
}
}
- (void)setRelationshipsOfModel:(id)object fromElements:(NSDictionary*)elements {
- (void)setRelationshipsOfModel:(NSObject<RKObjectMappable>*)object fromElements:(NSDictionary*)elements {
NSDictionary* elementToRelationshipMappings = [[object class] elementToRelationshipMappings];
for (NSString* elementKeyPath in elementToRelationshipMappings) {
NSString* propertyName = [elementToRelationshipMappings objectForKey:elementKeyPath];
@@ -413,7 +412,7 @@ static const NSString* kRKModelMapperMappingFormatParserKey = @"RKMappingFormatP
}
}
- (void)updateModel:(id)model fromElements:(NSDictionary*)elements {
- (void)updateModel:(NSObject<RKObjectMappable>*)model fromElements:(NSDictionary*)elements {
[self setPropertiesOfModel:model fromElements:elements];
[self setRelationshipsOfModel:model fromElements:elements];
}

View File

@@ -13,7 +13,7 @@
@implementation RKObjectPropertyInspector
- (id)init {
if (self = [super init]) {
if ((self = [super init])) {
_cachedPropertyNamesAndTypes = [[NSMutableDictionary alloc] init];
}
@@ -58,7 +58,6 @@
int i;
NSString *propName;
for (i = 0; i < outCount; i++) {
// TODO: Add support for custom getter and setter methods
// property_getAttributes() returns everything we need to implement this...
// See: http://developer.apple.com/mac/library/DOCUMENTATION/Cocoa/Conceptual/ObjCRuntimeGuide/Articles/ocrtPropertyIntrospection.html#//apple_ref/doc/uid/TP40008048-CH101-SW5
objc_property_t* prop = propList + i;
@@ -68,7 +67,6 @@
if (![propName isEqualToString:@"_mapkit_hasPanoramaID"]) {
const char* className = [[self propertyTypeFromAttributeString:attributeString] cStringUsingEncoding:NSUTF8StringEncoding];
Class class = objc_getClass(className);
// TODO: Use an id type if unable to get the class??
if (class) {
[propertyNames setObject:class forKey:propName];
}