Update headers for three20 support.

Add keyPath support to the object loader.
This commit is contained in:
timkerchmar
2010-10-12 14:32:06 -04:00
parent 30c96c8bf1
commit 320e96e48e
10 changed files with 110 additions and 32 deletions

View File

@@ -36,6 +36,7 @@
RKResponse* _response;
Class<RKObjectMappable> _objectClass;
NSFetchRequest* _fetchRequest;
NSString* _keyPath;
}
/**
@@ -96,6 +97,12 @@
*/
@property (nonatomic, retain) NSFetchRequest* fetchRequest;
/*
* The keyPath property is an optional property to tell the mapper to map a subset of the response
* defined by a specific key.
*/
@property (nonatomic, copy) NSString* keyPath;
/**
* Return an auto-released loader with with an object mapper, a request, and a delegate
*/

View File

@@ -20,7 +20,7 @@
@synthesize mapper = _mapper, delegate = _delegate, fetchRequest = _fetchRequest,
request = _request, response = _response, objectClass = _objectClass,
source = _source;
source = _source, keyPath = _keyPath;
+ (id)loaderWithMapper:(RKObjectMapper*)mapper request:(RKRequest*)request delegate:(NSObject<RKObjectLoaderDelegate>*)delegate {
return [[[self alloc] initWithMapper:mapper request:request delegate:delegate] autorelease];
@@ -42,6 +42,7 @@
[_request release];
[_response release];
[_fetchRequest release];
[_keyPath release];
[super dealloc];
}
@@ -176,7 +177,7 @@
}
} else {
id result = [_mapper mapFromString:[response bodyAsString] toClass:self.objectClass];
id result = [_mapper mapFromString:[response bodyAsString] toClass:self.objectClass keyPath:_keyPath];
if ([result isKindOfClass:[NSArray class]]) {
results = (NSArray*)result;
} else {

View File

@@ -108,6 +108,7 @@ static RKObjectManager* globalManager = nil;
NSURL* URL = [self.client URLForResourcePath:resourcePath];
RKRequest* request = [[[RKRequest alloc] initWithURL:URL] autorelease];
[self.client setupRequest:request];
RKObjectLoader* loader = [RKObjectLoader loaderWithMapper:self.mapper request:request delegate:delegate];
loader.objectClass = objectClass;

View File

@@ -101,8 +101,11 @@ static const NSString* kRKModelMapperMappingFormatParserKey = @"RKMappingFormatP
return result;
}
- (id)mapFromString:(NSString*)string toClass:(Class)class {
- (id)mapFromString:(NSString*)string toClass:(Class)class keyPath:(NSString*)keyPath {
id object = [self parseString:string];
if (keyPath) {
object = [object valueForKeyPath:keyPath];
}
if ([object isKindOfClass:[NSDictionary class]]) {
return [self mapObjectFromDictionary:(NSDictionary*)object];
} else if ([object isKindOfClass:[NSArray class]]) {