mirror of
https://github.com/zhigang1992/RestKit.git
synced 2026-04-11 11:39:05 +08:00
Update headers for three20 support.
Add keyPath support to the object loader.
This commit is contained in:
@@ -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
|
||||
*/
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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]]) {
|
||||
|
||||
Reference in New Issue
Block a user