mirror of
https://github.com/zhigang1992/RestKit.git
synced 2026-04-24 04:46:01 +08:00
Fixed breakage in OS X support
This commit is contained in:
@@ -50,7 +50,7 @@
|
||||
NSAssert(primaryKeyAttribute, @"Cannot connect relationship without primaryKeyAttribute");
|
||||
|
||||
RKObjectRelationshipMapping* relationshipMapping = [self.objectMapping mappingForRelationship:relationshipName];
|
||||
id<RKObjectMappingDefinition> mapping = relationshipMapping.mapping;
|
||||
RKObjectMappingDefinition *mapping = relationshipMapping.mapping;
|
||||
NSAssert(mapping, @"Attempted to connect relationship for keyPath '%@' without a relationship mapping defined.");
|
||||
if (! [mapping isKindOfClass:[RKObjectMapping class]]) {
|
||||
RKLogWarning(@"Can only connect relationships for RKObjectMapping relationships. Found %@: Skipping...", NSStringFromClass([mapping class]));
|
||||
|
||||
@@ -433,7 +433,7 @@ static NSString* const RKManagedObjectStoreThreadDictionaryEntityCacheKey = @"RK
|
||||
[fetchRequest setResultType:NSManagedObjectIDResultType];
|
||||
|
||||
objectIds = [NSManagedObject executeFetchRequest:fetchRequest];
|
||||
RKLogInfo(@"Caching all %d %@ objectsIDs to thread local storage", [objectIds count], entity.name);
|
||||
RKLogInfo(@"Caching all %ld %@ objectsIDs to thread local storage", (long) [objectIds count], entity.name);
|
||||
NSMutableDictionary* dictionary = [NSMutableDictionary dictionary];
|
||||
if ([objectIds count] > 0) {
|
||||
BOOL coerceToString = [self shouldCoerceAttributeToString:primaryKeyAttribute forEntity:entity];
|
||||
|
||||
@@ -214,7 +214,7 @@ static const NSTimeInterval kFlushDelay = 0.3;
|
||||
@synchronized(self) {
|
||||
[_loadingRequests addObject:request];
|
||||
}
|
||||
RKLogTrace(@"Loading count now %d for queue %@", self.loadingCount, self);
|
||||
RKLogTrace(@"Loading count now %ld for queue %@", (long) self.loadingCount, self);
|
||||
}
|
||||
|
||||
- (void)removeLoadingRequest:(RKRequest*)request {
|
||||
@@ -235,7 +235,7 @@ static const NSTimeInterval kFlushDelay = 0.3;
|
||||
@synchronized(self) {
|
||||
[_loadingRequests removeObject:request];
|
||||
}
|
||||
RKLogTrace(@"Loading count now %d for queue %@", self.loadingCount, self);
|
||||
RKLogTrace(@"Loading count now %ld for queue %@", (long) self.loadingCount, self);
|
||||
}
|
||||
|
||||
- (void)loadNextInQueueDelayed {
|
||||
@@ -468,7 +468,7 @@ static const NSTimeInterval kFlushDelay = 0.3;
|
||||
NSDictionary* userInfo = [notification userInfo];
|
||||
|
||||
// We successfully loaded a response
|
||||
RKLogDebug(@"Received response for request %@, removing from queue. (Now loading %d of %d)", request, self.loadingCount, _concurrentRequestsLimit);
|
||||
RKLogDebug(@"Received response for request %@, removing from queue. (Now loading %ld of %ld)", request, (long) self.loadingCount, (long) _concurrentRequestsLimit);
|
||||
|
||||
RKResponse* response = [userInfo objectForKey:RKRequestDidLoadResponseNotificationUserInfoResponseKey];
|
||||
if ([_delegate respondsToSelector:@selector(requestQueue:didLoadResponse:)]) {
|
||||
@@ -490,8 +490,8 @@ static const NSTimeInterval kFlushDelay = 0.3;
|
||||
NSError* error = nil;
|
||||
if (userInfo) {
|
||||
error = [userInfo objectForKey:RKRequestDidFailWithErrorNotificationUserInfoErrorKey];
|
||||
RKLogDebug(@"Request %@ failed loading in queue %@ with error: %@.(Now loading %d of %d)", request, self,
|
||||
[error localizedDescription], self.loadingCount, _concurrentRequestsLimit);
|
||||
RKLogDebug(@"Request %@ failed loading in queue %@ with error: %@.(Now loading %ld of %ld)", request, self,
|
||||
[error localizedDescription], (long) self.loadingCount, (long) _concurrentRequestsLimit);
|
||||
} else {
|
||||
RKLogWarning(@"Received RKRequestDidFailWithErrorNotification without a userInfo, something is amiss...");
|
||||
}
|
||||
|
||||
@@ -40,13 +40,12 @@ typedef RKObjectMapping*(^RKDynamicObjectMappingDelegateBlock)(id);
|
||||
object mapping to apply at mapping time. This allows you to map very similar payloads
|
||||
differently depending on the type of data contained therein.
|
||||
*/
|
||||
@interface RKDynamicObjectMapping : NSObject <RKObjectMappingDefinition> {
|
||||
@interface RKDynamicObjectMapping : RKObjectMappingDefinition {
|
||||
NSMutableArray *_matchers;
|
||||
id<RKDynamicObjectMappingDelegate> _delegate;
|
||||
#ifdef NS_BLOCKS_AVAILABLE
|
||||
RKDynamicObjectMappingDelegateBlock _objectMappingForDataBlock;
|
||||
#endif
|
||||
BOOL _forceCollectionMapping;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -65,13 +64,6 @@ typedef RKObjectMapping*(^RKDynamicObjectMappingDelegateBlock)(id);
|
||||
@property (nonatomic, copy) RKDynamicObjectMappingDelegateBlock objectMappingForDataBlock;
|
||||
#endif
|
||||
|
||||
/**
|
||||
When YES, an NSDictionary encountered by RKObjectMapper will be treated as a collection
|
||||
rather than as a single mappable entity. This is used to perform sub-keypath mapping wherein
|
||||
the keys of the dictionary are part of the mappable data.
|
||||
*/
|
||||
@property (nonatomic, assign) BOOL forceCollectionMapping;
|
||||
|
||||
/**
|
||||
Return a new auto-released dynamic object mapping
|
||||
*/
|
||||
|
||||
@@ -31,7 +31,6 @@
|
||||
|
||||
@synthesize delegate = _delegate;
|
||||
@synthesize objectMappingForDataBlock = _objectMappingForDataBlock;
|
||||
@synthesize forceCollectionMapping = _forceCollectionMapping;
|
||||
|
||||
+ (RKDynamicObjectMapping*)dynamicMapping {
|
||||
return [[self new] autorelease];
|
||||
|
||||
@@ -226,7 +226,7 @@
|
||||
return result;
|
||||
}
|
||||
|
||||
- (RKObjectMapping *)configuredObjectMapping {
|
||||
- (RKObjectMappingDefinition *)configuredObjectMapping {
|
||||
if (self.objectMapping) {
|
||||
return self.objectMapping;
|
||||
}
|
||||
@@ -238,7 +238,7 @@
|
||||
NSAssert(_sentSynchronously || ![NSThread isMainThread], @"Mapping should occur on a background thread");
|
||||
|
||||
RKObjectMappingProvider* mappingProvider;
|
||||
RKObjectMapping *configuredObjectMapping = [self configuredObjectMapping];
|
||||
RKObjectMappingDefinition *configuredObjectMapping = [self configuredObjectMapping];
|
||||
if (configuredObjectMapping) {
|
||||
mappingProvider = [RKObjectMappingProvider mappingProvider];
|
||||
NSString *rootKeyPath = configuredObjectMapping.rootKeyPath ? configuredObjectMapping.rootKeyPath : @"";
|
||||
|
||||
@@ -210,7 +210,7 @@ static dispatch_queue_t defaultMappingQueue = nil;
|
||||
loader.serializationMIMEType = self.serializationMIMEType;
|
||||
loader.serializationMapping = [self.mappingProvider serializationMappingForClass:[object class]];
|
||||
|
||||
id<RKObjectMappingDefinition> objectMapping = [self.mappingProvider objectMappingForResourcePath:resourcePath];
|
||||
RKObjectMappingDefinition * objectMapping = [self.mappingProvider objectMappingForResourcePath:resourcePath];
|
||||
if (objectMapping == nil || ([objectMapping isKindOfClass:[RKObjectMapping class]] && [object isMemberOfClass:[(RKObjectMapping *)objectMapping objectClass]])) {
|
||||
loader.targetObject = object;
|
||||
} else {
|
||||
|
||||
@@ -35,12 +35,12 @@
|
||||
- (void)objectMapperWillBeginMapping:(RKObjectMapper*)objectMapper;
|
||||
- (void)objectMapperDidFinishMapping:(RKObjectMapper*)objectMapper;
|
||||
- (void)objectMapper:(RKObjectMapper*)objectMapper didAddError:(NSError*)error;
|
||||
- (void)objectMapper:(RKObjectMapper*)objectMapper didFindMappableObject:(id)object atKeyPath:(NSString*)keyPath withMapping:(id<RKObjectMappingDefinition>)mapping;
|
||||
- (void)objectMapper:(RKObjectMapper*)objectMapper didFindMappableObject:(id)object atKeyPath:(NSString*)keyPath withMapping:(RKObjectMappingDefinition *)mapping;
|
||||
- (void)objectMapper:(RKObjectMapper*)objectMapper didNotFindMappableObjectAtKeyPath:(NSString*)keyPath;
|
||||
|
||||
- (void)objectMapper:(RKObjectMapper*)objectMapper willMapFromObject:(id)sourceObject toObject:(id)destinationObject atKeyPath:(NSString*)keyPath usingMapping:(id<RKObjectMappingDefinition>)objectMapping;
|
||||
- (void)objectMapper:(RKObjectMapper*)objectMapper didMapFromObject:(id)sourceObject toObject:(id)destinationObject atKeyPath:(NSString*)keyPath usingMapping:(id<RKObjectMappingDefinition>)objectMapping;
|
||||
- (void)objectMapper:(RKObjectMapper*)objectMapper didFailMappingFromObject:(id)sourceObject toObject:(id)destinationObject withError:(NSError*)error atKeyPath:(NSString*)keyPath usingMapping:(id<RKObjectMappingDefinition>)objectMapping;
|
||||
- (void)objectMapper:(RKObjectMapper*)objectMapper willMapFromObject:(id)sourceObject toObject:(id)destinationObject atKeyPath:(NSString*)keyPath usingMapping:(RKObjectMappingDefinition *)objectMapping;
|
||||
- (void)objectMapper:(RKObjectMapper*)objectMapper didMapFromObject:(id)sourceObject toObject:(id)destinationObject atKeyPath:(NSString*)keyPath usingMapping:(RKObjectMappingDefinition *)objectMapping;
|
||||
- (void)objectMapper:(RKObjectMapper*)objectMapper didFailMappingFromObject:(id)sourceObject toObject:(id)destinationObject withError:(NSError*)error atKeyPath:(NSString*)keyPath usingMapping:(RKObjectMappingDefinition *)objectMapping;
|
||||
@end
|
||||
|
||||
/**
|
||||
|
||||
@@ -118,7 +118,7 @@
|
||||
|
||||
#pragma mark - Mapping Primitives
|
||||
|
||||
- (id)mapObject:(id)mappableObject atKeyPath:(NSString *)keyPath usingMapping:(id<RKObjectMappingDefinition>)mapping {
|
||||
- (id)mapObject:(id)mappableObject atKeyPath:(NSString *)keyPath usingMapping:(RKObjectMappingDefinition *)mapping {
|
||||
NSAssert([mappableObject respondsToSelector:@selector(setValue:forKeyPath:)], @"Expected self.object to be KVC compliant");
|
||||
id destinationObject = nil;
|
||||
|
||||
@@ -157,7 +157,7 @@
|
||||
return nil;
|
||||
}
|
||||
|
||||
- (NSArray *)mapCollection:(NSArray *)mappableObjects atKeyPath:(NSString *)keyPath usingMapping:(id<RKObjectMappingDefinition>)mapping {
|
||||
- (NSArray *)mapCollection:(NSArray *)mappableObjects atKeyPath:(NSString *)keyPath usingMapping:(RKObjectMappingDefinition *)mapping {
|
||||
NSAssert(mappableObjects != nil, @"Cannot map without an collection of mappable objects");
|
||||
NSAssert(mapping != nil, @"Cannot map without a mapping to consult");
|
||||
|
||||
@@ -202,7 +202,7 @@
|
||||
}
|
||||
|
||||
// The workhorse of this entire process. Emits object loading operations
|
||||
- (BOOL)mapFromObject:(id)mappableObject toObject:(id)destinationObject atKeyPath:(NSString *)keyPath usingMapping:(id<RKObjectMappingDefinition>)mapping {
|
||||
- (BOOL)mapFromObject:(id)mappableObject toObject:(id)destinationObject atKeyPath:(NSString *)keyPath usingMapping:(RKObjectMappingDefinition *)mapping {
|
||||
NSAssert(destinationObject != nil, @"Cannot map without a target object to assign the results to");
|
||||
NSAssert(mappableObject != nil, @"Cannot map without a collection of attributes");
|
||||
NSAssert(mapping != nil, @"Cannot map without an mapping");
|
||||
@@ -234,8 +234,8 @@
|
||||
return success;
|
||||
}
|
||||
|
||||
- (id)objectWithMapping:(id<RKObjectMappingDefinition>)mapping andData:(id)mappableData {
|
||||
NSAssert([mapping conformsToProtocol:@protocol(RKObjectMappingDefinition)], @"Expected an object implementing RKObjectMappingDefinition");
|
||||
- (id)objectWithMapping:(RKObjectMappingDefinition *)mapping andData:(id)mappableData {
|
||||
NSAssert([mapping isKindOfClass:[RKObjectMappingDefinition class]], @"Expected an RKObjectMappingDefinition object");
|
||||
RKObjectMapping *objectMapping = nil;
|
||||
if ([mapping isKindOfClass:[RKDynamicObjectMapping class]]) {
|
||||
objectMapping = [(RKDynamicObjectMapping *)mapping objectMappingForDictionary:mappableData];
|
||||
@@ -255,7 +255,7 @@
|
||||
return nil;
|
||||
}
|
||||
|
||||
- (id)performMappingForObject:(id)mappableValue atKeyPath:(NSString *)keyPath usingMapping:(id<RKObjectMappingDefinition>)mapping {
|
||||
- (id)performMappingForObject:(id)mappableValue atKeyPath:(NSString *)keyPath usingMapping:(RKObjectMappingDefinition *)mapping {
|
||||
id mappingResult;
|
||||
if (mapping.forceCollectionMapping || [mappableValue isKindOfClass:[NSArray class]] || [mappableValue isKindOfClass:[NSSet class]]) {
|
||||
RKLogDebug(@"Found mappable collection at keyPath '%@': %@", keyPath, mappableValue);
|
||||
@@ -296,7 +296,7 @@
|
||||
|
||||
// Found something to map
|
||||
foundMappable = YES;
|
||||
id<RKObjectMappingDefinition> mapping = [mappingsByKeyPath objectForKey:keyPath];
|
||||
RKObjectMappingDefinition * mapping = [mappingsByKeyPath objectForKey:keyPath];
|
||||
if ([self.delegate respondsToSelector:@selector(objectMapper:didFindMappableObject:atKeyPath:withMapping:)]) {
|
||||
[self.delegate objectMapper:self didFindMappableObject:mappableValue atKeyPath:keyPath withMapping:mapping];
|
||||
}
|
||||
@@ -332,9 +332,9 @@
|
||||
if ([mappingsForContext isKindOfClass:[NSDictionary class]]) {
|
||||
results = [self performKeyPathMappingUsingMappingDictionary:mappingsForContext];
|
||||
foundMappable = (results != nil);
|
||||
} else if ([mappingsForContext conformsToProtocol:@protocol(RKObjectMappingDefinition)]) {
|
||||
} else if ([mappingsForContext isKindOfClass:[RKObjectMappingDefinition class]]) {
|
||||
id mappableData = self.sourceObject;
|
||||
if ([mappingsForContext respondsToSelector:@selector(rootKeyPath)] && [mappingsForContext rootKeyPath] != nil) {
|
||||
if ([mappingsForContext rootKeyPath] != nil) {
|
||||
NSString* rootKeyPath = [mappingsForContext rootKeyPath];
|
||||
mappableData = [self.sourceObject valueForKeyPath:rootKeyPath];
|
||||
RKLogDebug(@"Selected object mapping has rootKeyPath. Apply valueForKeyPath to mappable data: %@", rootKeyPath);
|
||||
|
||||
@@ -20,9 +20,9 @@
|
||||
|
||||
@interface RKObjectMapper (Private)
|
||||
|
||||
- (id)mapObject:(id)mappableObject atKeyPath:(NSString *)keyPath usingMapping:(id<RKObjectMappingDefinition>)mapping;
|
||||
- (NSArray*)mapCollection:(NSArray*)mappableObjects atKeyPath:(NSString*)keyPath usingMapping:(id<RKObjectMappingDefinition>)mapping;
|
||||
- (BOOL)mapFromObject:(id)mappableObject toObject:(id)destinationObject atKeyPath:(NSString *)keyPath usingMapping:(id<RKObjectMappingDefinition>)mapping;
|
||||
- (id)objectWithMapping:(id<RKObjectMappingDefinition>)objectMapping andData:(id)mappableData;
|
||||
- (id)mapObject:(id)mappableObject atKeyPath:(NSString *)keyPath usingMapping:(RKObjectMappingDefinition *)mapping;
|
||||
- (NSArray*)mapCollection:(NSArray*)mappableObjects atKeyPath:(NSString*)keyPath usingMapping:(RKObjectMappingDefinition *)mapping;
|
||||
- (BOOL)mapFromObject:(id)mappableObject toObject:(id)destinationObject atKeyPath:(NSString *)keyPath usingMapping:(RKObjectMappingDefinition *)mapping;
|
||||
- (id)objectWithMapping:(RKObjectMappingDefinition *)objectMapping andData:(id)mappableData;
|
||||
|
||||
@end
|
||||
|
||||
@@ -43,13 +43,12 @@ relationship. Relationships are processed using an object mapping as well.
|
||||
Instances of RKObjectMapping are used to configure RKObjectMappingOperation instances, which actually
|
||||
perform the mapping work. Both object loading and serialization are defined in terms of object mappings.
|
||||
*/
|
||||
@interface RKObjectMapping : NSObject <RKObjectMappingDefinition, NSCopying> {
|
||||
@interface RKObjectMapping : RKObjectMappingDefinition <NSCopying> {
|
||||
Class _objectClass;
|
||||
NSMutableArray* _mappings;
|
||||
NSString* _rootKeyPath;
|
||||
BOOL _setDefaultValueForMissingAttributes;
|
||||
BOOL _setNilForMissingRelationships;
|
||||
BOOL _forceCollectionMapping;
|
||||
BOOL _performKeyValueValidation;
|
||||
NSArray *_dateFormatters;
|
||||
NSFormatter *_preferredDateFormatter;
|
||||
@@ -63,36 +62,23 @@ relationship. Relationships are processed using an object mapping as well.
|
||||
/**
|
||||
The aggregate collection of attribute and relationship mappings within this object mapping
|
||||
*/
|
||||
@property (nonatomic, readonly) NSArray* mappings;
|
||||
@property (nonatomic, readonly) NSArray *mappings;
|
||||
|
||||
/**
|
||||
The collection of attribute mappings within this object mapping
|
||||
*/
|
||||
@property (nonatomic, readonly) NSArray* attributeMappings;
|
||||
@property (nonatomic, readonly) NSArray *attributeMappings;
|
||||
|
||||
/**
|
||||
The collection of relationship mappings within this object mapping
|
||||
*/
|
||||
@property (nonatomic, readonly) NSArray* relationshipMappings;
|
||||
@property (nonatomic, readonly) NSArray *relationshipMappings;
|
||||
|
||||
/**
|
||||
The collection of mappable keyPaths that are defined within this object mapping. These
|
||||
keyPaths refer to keys within the source object being mapped (i.e. the parsed JSON payload).
|
||||
*/
|
||||
@property (nonatomic, readonly) NSArray* mappedKeyPaths;
|
||||
|
||||
/**
|
||||
The root key path for the receiver.
|
||||
|
||||
Root key paths are handled differently depending on the context in which the mapping is
|
||||
being used. If the receiver is used for object mapping, the rootKeyPath specifies a nested
|
||||
root dictionary that all attribute and relationship mappings will be considered relative to. When
|
||||
the mapping is used in a serialization context, the rootKeyPath specifies that the serialized content
|
||||
should be stored in a dictionary nested with the rootKeyPath as the key.
|
||||
|
||||
@see RKObjectSerializer
|
||||
*/
|
||||
@property (nonatomic, retain) NSString* rootKeyPath;
|
||||
@property (nonatomic, readonly) NSArray *mappedKeyPaths;
|
||||
|
||||
/**
|
||||
When YES, any attributes that have mappings defined but are not present within the source
|
||||
@@ -120,38 +106,13 @@ relationship. Relationships are processed using an object mapping as well.
|
||||
be ignored and mapping will continue. When NO, unknown keyPath mappings will generate
|
||||
NSUnknownKeyException errors for the unknown keyPath.
|
||||
|
||||
Defaulted to NO to help the developer catch incorrect mapping configurations during
|
||||
Defaults to NO to help the developer catch incorrect mapping configurations during
|
||||
development.
|
||||
|
||||
**Default**: NO
|
||||
*/
|
||||
@property (nonatomic, assign) BOOL ignoreUnknownKeyPaths;
|
||||
|
||||
/**
|
||||
Forces the mapper to treat the mapped keyPath as a collection even if it does not
|
||||
return an array or a set of objects. This permits mapping where a dictionary identifies
|
||||
a collection of objects.
|
||||
|
||||
When enabled, each key/value pair in the resolved dictionary will be mapped as a separate
|
||||
entity. This is useful when you have a JSON structure similar to:
|
||||
|
||||
{ "users":
|
||||
{
|
||||
"blake": { "id": 1234, "email": "blake@restkit.org" },
|
||||
"rachit": { "id": 5678", "email": "rachit@restkit.org" }
|
||||
}
|
||||
}
|
||||
|
||||
By enabling forceCollectionMapping, RestKit will map "blake" => attributes and
|
||||
"rachit" => attributes as independent objects. This can be combined with
|
||||
mapKeyOfNestedDictionaryToAttribute: to properly map these sorts of structures.
|
||||
|
||||
@default NO
|
||||
@see mapKeyOfNestedDictionaryToAttribute
|
||||
*/
|
||||
@property (nonatomic, assign) BOOL forceCollectionMapping;
|
||||
|
||||
|
||||
/**
|
||||
An array of NSDateFormatter objects to use when mapping string values
|
||||
into NSDate attributes on the target objectClass. Each date formatter
|
||||
@@ -353,7 +314,7 @@ relationship. Relationships are processed using an object mapping as well.
|
||||
on the destination class that have the same name.
|
||||
@param objectOrDynamicMapping An RKObjectMapping or RKObjectDynamic mapping to apply when mapping the relationship
|
||||
*/
|
||||
- (void)mapRelationship:(NSString*)relationshipKey withMapping:(id<RKObjectMappingDefinition>)objectOrDynamicMapping;
|
||||
- (void)mapRelationship:(NSString*)relationshipKey withMapping:(RKObjectMappingDefinition *)objectOrDynamicMapping;
|
||||
|
||||
/**
|
||||
Syntactic sugar to improve readability when defining a relationship mapping. Implies that the mapping
|
||||
@@ -361,7 +322,7 @@ relationship. Relationships are processed using an object mapping as well.
|
||||
|
||||
@see mapRelationship:withObjectMapping:
|
||||
*/
|
||||
- (void)hasMany:(NSString*)keyPath withMapping:(id<RKObjectMappingDefinition>)objectOrDynamicMapping;
|
||||
- (void)hasMany:(NSString*)keyPath withMapping:(RKObjectMappingDefinition *)objectOrDynamicMapping;
|
||||
|
||||
/**
|
||||
Syntactic sugar to improve readability when defining a relationship mapping. Implies that the mapping
|
||||
@@ -369,7 +330,7 @@ relationship. Relationships are processed using an object mapping as well.
|
||||
|
||||
@see mapRelationship:withObjectMapping:
|
||||
*/
|
||||
- (void)hasOne:(NSString*)keyPath withMapping:(id<RKObjectMappingDefinition>)objectOrDynamicMapping;
|
||||
- (void)hasOne:(NSString*)keyPath withMapping:(RKObjectMappingDefinition *)objectOrDynamicMapping;
|
||||
|
||||
/**
|
||||
Instantiate and add an RKObjectAttributeMapping instance targeting a keyPath within the mappable
|
||||
@@ -410,7 +371,7 @@ relationship. Relationships are processed using an object mapping as well.
|
||||
@param objectMapping An object mapping to use when processing the nested objects
|
||||
@see RKObjectRelationshipMapping
|
||||
*/
|
||||
- (void)mapKeyPath:(NSString *)sourceKeyPath toRelationship:(NSString*)destinationRelationship withMapping:(id<RKObjectMappingDefinition>)objectOrDynamicMapping;
|
||||
- (void)mapKeyPath:(NSString *)sourceKeyPath toRelationship:(NSString*)destinationRelationship withMapping:(RKObjectMappingDefinition *)objectOrDynamicMapping;
|
||||
|
||||
/**
|
||||
Instantiate and add an RKObjectRelationshipMapping instance targeting a keyPath within the mappable
|
||||
@@ -425,7 +386,7 @@ relationship. Relationships are processed using an object mapping as well.
|
||||
|
||||
@see mapKeyPath:toRelationship:withObjectMapping:
|
||||
*/
|
||||
- (void)mapKeyPath:(NSString *)relationshipKeyPath toRelationship:(NSString*)keyPath withMapping:(id<RKObjectMappingDefinition>)objectOrDynamicMapping serialize:(BOOL)serialize;
|
||||
- (void)mapKeyPath:(NSString *)relationshipKeyPath toRelationship:(NSString*)keyPath withMapping:(RKObjectMappingDefinition *)objectOrDynamicMapping serialize:(BOOL)serialize;
|
||||
|
||||
/**
|
||||
Quickly define a group of attribute mappings using alternating keyPath and attribute names. You must provide
|
||||
|
||||
@@ -36,7 +36,6 @@ NSString* const RKObjectMappingNestingAttributeKeyName = @"<RK_NESTING_ATTRIBUTE
|
||||
@synthesize rootKeyPath = _rootKeyPath;
|
||||
@synthesize setDefaultValueForMissingAttributes = _setDefaultValueForMissingAttributes;
|
||||
@synthesize setNilForMissingRelationships = _setNilForMissingRelationships;
|
||||
@synthesize forceCollectionMapping = _forceCollectionMapping;
|
||||
@synthesize performKeyValueValidation = _performKeyValueValidation;
|
||||
@synthesize ignoreUnknownKeyPaths = _ignoreUnknownKeyPaths;
|
||||
|
||||
@@ -212,16 +211,16 @@ NSString* const RKObjectMappingNestingAttributeKeyName = @"<RK_NESTING_ATTRIBUTE
|
||||
[self mapAttributesCollection:[NSSet setWithArray:array]];
|
||||
}
|
||||
|
||||
- (void)mapKeyPath:(NSString *)relationshipKeyPath toRelationship:(NSString*)keyPath withMapping:(id<RKObjectMappingDefinition>)objectOrDynamicMapping serialize:(BOOL)serialize {
|
||||
- (void)mapKeyPath:(NSString *)relationshipKeyPath toRelationship:(NSString*)keyPath withMapping:(RKObjectMappingDefinition *)objectOrDynamicMapping serialize:(BOOL)serialize {
|
||||
RKObjectRelationshipMapping* mapping = [RKObjectRelationshipMapping mappingFromKeyPath:relationshipKeyPath toKeyPath:keyPath withMapping:objectOrDynamicMapping reversible:serialize];
|
||||
[self addRelationshipMapping:mapping];
|
||||
}
|
||||
|
||||
- (void)mapKeyPath:(NSString *)relationshipKeyPath toRelationship:(NSString*)keyPath withMapping:(id<RKObjectMappingDefinition>)objectOrDynamicMapping {
|
||||
- (void)mapKeyPath:(NSString *)relationshipKeyPath toRelationship:(NSString*)keyPath withMapping:(RKObjectMappingDefinition *)objectOrDynamicMapping {
|
||||
[self mapKeyPath:relationshipKeyPath toRelationship:keyPath withMapping:objectOrDynamicMapping serialize:YES];
|
||||
}
|
||||
|
||||
- (void)mapRelationship:(NSString*)relationshipKeyPath withMapping:(id<RKObjectMappingDefinition>)objectOrDynamicMapping {
|
||||
- (void)mapRelationship:(NSString*)relationshipKeyPath withMapping:(RKObjectMappingDefinition *)objectOrDynamicMapping {
|
||||
[self mapKeyPath:relationshipKeyPath toRelationship:relationshipKeyPath withMapping:objectOrDynamicMapping];
|
||||
}
|
||||
|
||||
@@ -230,11 +229,11 @@ NSString* const RKObjectMappingNestingAttributeKeyName = @"<RK_NESTING_ATTRIBUTE
|
||||
[self addAttributeMapping:mapping];
|
||||
}
|
||||
|
||||
- (void)hasMany:(NSString*)keyPath withMapping:(id<RKObjectMappingDefinition>)objectOrDynamicMapping {
|
||||
- (void)hasMany:(NSString*)keyPath withMapping:(RKObjectMappingDefinition *)objectOrDynamicMapping {
|
||||
[self mapRelationship:keyPath withMapping:objectOrDynamicMapping];
|
||||
}
|
||||
|
||||
- (void)hasOne:(NSString*)keyPath withMapping:(id<RKObjectMappingDefinition>)objectOrDynamicMapping {
|
||||
- (void)hasOne:(NSString*)keyPath withMapping:(RKObjectMappingDefinition *)objectOrDynamicMapping {
|
||||
[self mapRelationship:keyPath withMapping:objectOrDynamicMapping];
|
||||
}
|
||||
|
||||
@@ -263,7 +262,7 @@ NSString* const RKObjectMappingNestingAttributeKeyName = @"<RK_NESTING_ATTRIBUTE
|
||||
|
||||
for (RKObjectRelationshipMapping* relationshipMapping in self.relationshipMappings) {
|
||||
if (relationshipMapping.reversible) {
|
||||
id<RKObjectMappingDefinition> mapping = relationshipMapping.mapping;
|
||||
RKObjectMappingDefinition * mapping = relationshipMapping.mapping;
|
||||
if (! [mapping isKindOfClass:[RKObjectMapping class]]) {
|
||||
RKLogWarning(@"Unable to generate inverse mapping for relationship '%@': %@ relationships cannot be inversed.", relationshipMapping.sourceKeyPath, NSStringFromClass([mapping class]));
|
||||
continue;
|
||||
|
||||
@@ -18,8 +18,48 @@
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
@protocol RKObjectMappingDefinition <NSObject>
|
||||
/**
|
||||
RKObjectMappingDefinition is an abstract class for objects defining RestKit object mappings.
|
||||
Its interface is common to all object mapping classes, including its concrete subclasses
|
||||
RKObjectMapping and RKDynamicObjectMapping.
|
||||
*/
|
||||
@interface RKObjectMappingDefinition : NSObject
|
||||
|
||||
- (BOOL)forceCollectionMapping;
|
||||
/**
|
||||
The root key path for the receiver.
|
||||
|
||||
Root key paths are handled differently depending on the context in which the mapping is
|
||||
being used. If the receiver is used for object mapping, the rootKeyPath specifies a nested
|
||||
root dictionary that all attribute and relationship mappings will be considered relative to. When
|
||||
the mapping is used in a serialization context, the rootKeyPath specifies that the serialized content
|
||||
should be stored in a dictionary nested with the rootKeyPath as the key.
|
||||
|
||||
@see RKObjectSerializer
|
||||
*/
|
||||
@property (nonatomic, copy) NSString *rootKeyPath;
|
||||
|
||||
@end
|
||||
/**
|
||||
Forces the mapper to treat the mapped keyPath as a collection even if it does not
|
||||
return an array or a set of objects. This permits mapping where a dictionary identifies
|
||||
a collection of objects.
|
||||
|
||||
When enabled, each key/value pair in the resolved dictionary will be mapped as a separate
|
||||
entity. This is useful when you have a JSON structure similar to:
|
||||
|
||||
{ "users":
|
||||
{
|
||||
"blake": { "id": 1234, "email": "blake@restkit.org" },
|
||||
"rachit": { "id": 5678", "email": "rachit@restkit.org" }
|
||||
}
|
||||
}
|
||||
|
||||
By enabling forceCollectionMapping, RestKit will map "blake" => attributes and
|
||||
"rachit" => attributes as independent objects. This can be combined with
|
||||
mapKeyOfNestedDictionaryToAttribute: to properly map these sorts of structures.
|
||||
|
||||
@default NO
|
||||
@see mapKeyOfNestedDictionaryToAttribute
|
||||
*/
|
||||
@property (nonatomic, assign) BOOL forceCollectionMapping;
|
||||
|
||||
@end
|
||||
|
||||
16
Code/ObjectMapping/RKObjectMappingDefinition.m
Normal file
16
Code/ObjectMapping/RKObjectMappingDefinition.m
Normal file
@@ -0,0 +1,16 @@
|
||||
//
|
||||
// RKObjectMappingDefinition.m
|
||||
// RestKit
|
||||
//
|
||||
// Created by Blake Watters on 2/15/12.
|
||||
// Copyright (c) 2012 RestKit. All rights reserved.
|
||||
//
|
||||
|
||||
#import "RKObjectMappingDefinition.h"
|
||||
|
||||
@implementation RKObjectMappingDefinition
|
||||
|
||||
@synthesize rootKeyPath;
|
||||
@synthesize forceCollectionMapping;
|
||||
|
||||
@end
|
||||
@@ -87,12 +87,12 @@
|
||||
|
||||
@return An instance of RKObjectMappingOperation or RKManagedObjectMappingOperation for performing the mapping
|
||||
*/
|
||||
+ (id)mappingOperationFromObject:(id)sourceObject toObject:(id)destinationObject withMapping:(id<RKObjectMappingDefinition>)mapping;
|
||||
+ (id)mappingOperationFromObject:(id)sourceObject toObject:(id)destinationObject withMapping:(RKObjectMappingDefinition *)mapping;
|
||||
|
||||
/**
|
||||
Initialize a mapping operation for an object and set of data at a particular key path with an object mapping definition
|
||||
*/
|
||||
- (id)initWithSourceObject:(id)sourceObject destinationObject:(id)destinationObject mapping:(id<RKObjectMappingDefinition>)mapping;
|
||||
- (id)initWithSourceObject:(id)sourceObject destinationObject:(id)destinationObject mapping:(RKObjectMappingDefinition *)mapping;
|
||||
|
||||
/**
|
||||
Process all mappable values from the mappable dictionary and assign them to the target object
|
||||
|
||||
@@ -69,7 +69,7 @@ BOOL RKObjectIsValueEqualToValue(id sourceValue, id destinationValue) {
|
||||
@synthesize delegate = _delegate;
|
||||
@synthesize queue = _queue;
|
||||
|
||||
+ (id)mappingOperationFromObject:(id)sourceObject toObject:(id)destinationObject withMapping:(id<RKObjectMappingDefinition>)objectMapping {
|
||||
+ (id)mappingOperationFromObject:(id)sourceObject toObject:(id)destinationObject withMapping:(RKObjectMappingDefinition *)objectMapping {
|
||||
// Check for availability of ManagedObjectMappingOperation. Better approach for handling?
|
||||
Class targetClass = NSClassFromString(@"RKManagedObjectMappingOperation");
|
||||
if (targetClass == nil) targetClass = [RKObjectMappingOperation class];
|
||||
@@ -77,7 +77,7 @@ BOOL RKObjectIsValueEqualToValue(id sourceValue, id destinationValue) {
|
||||
return [[[targetClass alloc] initWithSourceObject:sourceObject destinationObject:destinationObject mapping:objectMapping] autorelease];
|
||||
}
|
||||
|
||||
- (id)initWithSourceObject:(id)sourceObject destinationObject:(id)destinationObject mapping:(id<RKObjectMappingDefinition>)objectMapping {
|
||||
- (id)initWithSourceObject:(id)sourceObject destinationObject:(id)destinationObject mapping:(RKObjectMappingDefinition *)objectMapping {
|
||||
NSAssert(sourceObject != nil, @"Cannot perform a mapping operation without a sourceObject object");
|
||||
NSAssert(destinationObject != nil, @"Cannot perform a mapping operation without a destinationObject");
|
||||
NSAssert(objectMapping != nil, @"Cannot perform a mapping operation without a mapping");
|
||||
@@ -501,7 +501,7 @@ BOOL RKObjectIsValueEqualToValue(id sourceValue, id destinationValue) {
|
||||
RKLogWarning(@"Key path '%@' yielded collection containing another collection rather than a collection of objects: %@", relationshipMapping.sourceKeyPath, value);
|
||||
}
|
||||
for (id nestedObject in value) {
|
||||
id<RKObjectMappingDefinition> mapping = relationshipMapping.mapping;
|
||||
RKObjectMappingDefinition * mapping = relationshipMapping.mapping;
|
||||
RKObjectMapping* objectMapping = nil;
|
||||
if ([mapping isKindOfClass:[RKDynamicObjectMapping class]]) {
|
||||
objectMapping = [(RKDynamicObjectMapping*)mapping objectMappingForDictionary:nestedObject];
|
||||
@@ -549,7 +549,7 @@ BOOL RKObjectIsValueEqualToValue(id sourceValue, id destinationValue) {
|
||||
// One to one relationship
|
||||
RKLogDebug(@"Mapping one to one relationship value at keyPath '%@' to '%@'", relationshipMapping.sourceKeyPath, relationshipMapping.destinationKeyPath);
|
||||
|
||||
id<RKObjectMappingDefinition> mapping = relationshipMapping.mapping;
|
||||
RKObjectMappingDefinition * mapping = relationshipMapping.mapping;
|
||||
RKObjectMapping* objectMapping = nil;
|
||||
if ([mapping isKindOfClass:[RKDynamicObjectMapping class]]) {
|
||||
objectMapping = [(RKDynamicObjectMapping*)mapping objectMappingForDictionary:value];
|
||||
|
||||
@@ -28,21 +28,21 @@
|
||||
- (id)valueForContext:(RKObjectMappingProviderContext)context;
|
||||
- (void)setValue:(id)value forContext:(RKObjectMappingProviderContext)context;
|
||||
|
||||
- (id<RKObjectMappingDefinition>)mappingForContext:(RKObjectMappingProviderContext)context;
|
||||
- (RKObjectMappingDefinition *)mappingForContext:(RKObjectMappingProviderContext)context;
|
||||
/**
|
||||
Stores a single object mapping for a given context. Useful when a component needs to enable
|
||||
configuration via one (and only one) object mapping.
|
||||
*/
|
||||
- (void)setMapping:(id<RKObjectMappingDefinition>)mapping context:(RKObjectMappingProviderContext)context;
|
||||
- (void)setMapping:(RKObjectMappingDefinition *)mapping context:(RKObjectMappingProviderContext)context;
|
||||
- (NSArray *)mappingsForContext:(RKObjectMappingProviderContext)context;
|
||||
- (void)addMapping:(id<RKObjectMappingDefinition>)mapping context:(RKObjectMappingProviderContext)context;
|
||||
- (void)removeMapping:(id<RKObjectMappingDefinition>)mapping context:(RKObjectMappingProviderContext)context;
|
||||
- (id<RKObjectMappingDefinition>)mappingForKeyPath:(NSString *)keyPath context:(RKObjectMappingProviderContext)context;
|
||||
- (void)setMapping:(id<RKObjectMappingDefinition>)mapping forKeyPath:(NSString *)keyPath context:(RKObjectMappingProviderContext)context;
|
||||
- (void)addMapping:(RKObjectMappingDefinition *)mapping context:(RKObjectMappingProviderContext)context;
|
||||
- (void)removeMapping:(RKObjectMappingDefinition *)mapping context:(RKObjectMappingProviderContext)context;
|
||||
- (RKObjectMappingDefinition *)mappingForKeyPath:(NSString *)keyPath context:(RKObjectMappingProviderContext)context;
|
||||
- (void)setMapping:(RKObjectMappingDefinition *)mapping forKeyPath:(NSString *)keyPath context:(RKObjectMappingProviderContext)context;
|
||||
- (void)removeMappingForKeyPath:(NSString *)keyPath context:(RKObjectMappingProviderContext)context;
|
||||
|
||||
- (void)setMapping:(id<RKObjectMappingDefinition>)mapping forPattern:(NSString *)pattern atIndex:(NSUInteger)index context:(RKObjectMappingProviderContext)context;
|
||||
- (void)setMapping:(id<RKObjectMappingDefinition>)mapping forPattern:(NSString *)pattern context:(RKObjectMappingProviderContext)context;
|
||||
- (id<RKObjectMappingDefinition>)mappingForPatternMatchingString:(NSString *)string context:(RKObjectMappingProviderContext)context;
|
||||
- (void)setMapping:(RKObjectMappingDefinition *)mapping forPattern:(NSString *)pattern atIndex:(NSUInteger)index context:(RKObjectMappingProviderContext)context;
|
||||
- (void)setMapping:(RKObjectMappingDefinition *)mapping forPattern:(NSString *)pattern context:(RKObjectMappingProviderContext)context;
|
||||
- (RKObjectMappingDefinition *)mappingForPatternMatchingString:(NSString *)string context:(RKObjectMappingProviderContext)context;
|
||||
|
||||
@end
|
||||
|
||||
@@ -82,7 +82,7 @@ typedef enum {
|
||||
@see RKObjectMapper
|
||||
@see RKObjectMappingOperation
|
||||
*/
|
||||
- (void)setObjectMapping:(id<RKObjectMappingDefinition>)objectOrDynamicMapping forKeyPath:(NSString *)keyPath;
|
||||
- (void)setObjectMapping:(RKObjectMappingDefinition *)objectOrDynamicMapping forKeyPath:(NSString *)keyPath;
|
||||
|
||||
/**
|
||||
Returns the RKObjectMapping or RKObjectDynamic mapping configured for use
|
||||
@@ -91,7 +91,7 @@ typedef enum {
|
||||
@param keyPath A registered keyPath to retrieve the object mapping for
|
||||
@return The RKObjectMapping or RKDynamicObjectMapping for the specified keyPath or nil if none is registered.
|
||||
*/
|
||||
- (id<RKObjectMappingDefinition>)objectMappingForKeyPath:(NSString *)keyPath;
|
||||
- (RKObjectMappingDefinition *)objectMappingForKeyPath:(NSString *)keyPath;
|
||||
|
||||
/**
|
||||
Removes the RKObjectMapping or RKDynamicObjectMapping registered at the specified keyPath
|
||||
@@ -231,7 +231,7 @@ typedef enum {
|
||||
@see RKURL
|
||||
@see RKObjectLoader
|
||||
*/
|
||||
- (void)setObjectMapping:(id<RKObjectMappingDefinition>)objectMapping forResourcePathPattern:(NSString *)resourcePathPattern;
|
||||
- (void)setObjectMapping:(RKObjectMappingDefinition *)objectMapping forResourcePathPattern:(NSString *)resourcePathPattern;
|
||||
|
||||
/**
|
||||
Returns the first objectMapping configured in the provider with a resourcePathPattern matching
|
||||
@@ -242,7 +242,7 @@ typedef enum {
|
||||
@return An RKObjectMapping or RKDynamicObjectMapping for a resource path pattern matching resourcePath
|
||||
or nil if no match was found.
|
||||
*/
|
||||
- (id<RKObjectMappingDefinition>)objectMappingForResourcePath:(NSString *)resourcePath;
|
||||
- (RKObjectMappingDefinition *)objectMappingForResourcePath:(NSString *)resourcePath;
|
||||
|
||||
/**
|
||||
An object mapping used when the remote system returns an error status code
|
||||
@@ -277,8 +277,8 @@ typedef enum {
|
||||
@interface RKObjectMappingProvider (CompatibilityAliases)
|
||||
+ (RKObjectMappingProvider *)objectMappingProvider;
|
||||
- (void)registerMapping:(RKObjectMapping *)objectMapping withRootKeyPath:(NSString *)keyPath;
|
||||
- (void)setMapping:(id<RKObjectMappingDefinition>)objectOrDynamicMapping forKeyPath:(NSString *)keyPath;
|
||||
- (id<RKObjectMappingDefinition>)mappingForKeyPath:(NSString *)keyPath;
|
||||
- (void)setMapping:(RKObjectMappingDefinition *)objectOrDynamicMapping forKeyPath:(NSString *)keyPath;
|
||||
- (RKObjectMappingDefinition *)mappingForKeyPath:(NSString *)keyPath;
|
||||
- (NSDictionary *)mappingsByKeyPath;
|
||||
- (void)removeMappingForKeyPath:(NSString *)keyPath;
|
||||
@end
|
||||
|
||||
@@ -53,7 +53,7 @@
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
- (void)setObjectMapping:(id<RKObjectMappingDefinition>)objectOrDynamicMapping forKeyPath:(NSString *)keyPath {
|
||||
- (void)setObjectMapping:(RKObjectMappingDefinition *)objectOrDynamicMapping forKeyPath:(NSString *)keyPath {
|
||||
[self setMapping:objectOrDynamicMapping forKeyPath:keyPath context:RKObjectMappingProviderContextObjectsByKeyPath];
|
||||
}
|
||||
|
||||
@@ -61,7 +61,7 @@
|
||||
[self removeMappingForKeyPath:keyPath context:RKObjectMappingProviderContextObjectsByKeyPath];
|
||||
}
|
||||
|
||||
- (id<RKObjectMappingDefinition>)objectMappingForKeyPath:(NSString *)keyPath {
|
||||
- (RKObjectMappingDefinition *)objectMappingForKeyPath:(NSString *)keyPath {
|
||||
return [self mappingForKeyPath:keyPath context:RKObjectMappingProviderContextObjectsByKeyPath];
|
||||
}
|
||||
|
||||
@@ -95,7 +95,7 @@
|
||||
NSArray *mappingByType = [self valueForContext:RKObjectMappingProviderContextObjectsByType];
|
||||
NSArray *mappingByKeyPath = [[self valueForContext:RKObjectMappingProviderContextObjectsByKeyPath] allValues];
|
||||
NSArray *mappingsToSearch = [[NSArray arrayWithArray:mappingByType] arrayByAddingObjectsFromArray:mappingByKeyPath];
|
||||
for (NSObject <RKObjectMappingDefinition> *candidateMapping in mappingsToSearch) {
|
||||
for (RKObjectMappingDefinition *candidateMapping in mappingsToSearch) {
|
||||
if ( ![candidateMapping respondsToSelector:@selector(objectClass)] || [mappings containsObject:candidateMapping])
|
||||
continue;
|
||||
Class mappedClass = [candidateMapping performSelector:@selector(objectClass)];
|
||||
@@ -133,11 +133,11 @@
|
||||
[self setMapping:paginationMapping context:RKObjectMappingProviderContextPagination];
|
||||
}
|
||||
|
||||
- (void)setObjectMapping:(id<RKObjectMappingDefinition>)objectMapping forResourcePathPattern:(NSString *)resourcePath {
|
||||
- (void)setObjectMapping:(RKObjectMappingDefinition *)objectMapping forResourcePathPattern:(NSString *)resourcePath {
|
||||
[self setMapping:objectMapping forPattern:resourcePath context:RKObjectMappingProviderContextObjectsByResourcePathPattern];
|
||||
}
|
||||
|
||||
- (id<RKObjectMappingDefinition>)objectMappingForResourcePath:(NSString *)resourcePath {
|
||||
- (RKObjectMappingDefinition *)objectMappingForResourcePath:(NSString *)resourcePath {
|
||||
return [self mappingForPatternMatchingString:resourcePath context:RKObjectMappingProviderContextObjectsByResourcePathPattern];
|
||||
}
|
||||
|
||||
@@ -163,16 +163,16 @@
|
||||
NSAssert([contextValue isKindOfClass:theClass], @"Storage type mismatch for context %d: expected a %@, got %@.", context, theClass, [contextValue class]);
|
||||
}
|
||||
|
||||
- (void)setMapping:(id<RKObjectMappingDefinition>)mapping context:(RKObjectMappingProviderContext)context {
|
||||
- (void)setMapping:(RKObjectMappingDefinition *)mapping context:(RKObjectMappingProviderContext)context {
|
||||
NSNumber *contextNumber = [NSNumber numberWithInteger:context];
|
||||
[mappingContexts setObject:mapping forKey:contextNumber];
|
||||
}
|
||||
|
||||
- (id<RKObjectMappingDefinition>)mappingForContext:(RKObjectMappingProviderContext)context {
|
||||
- (RKObjectMappingDefinition *)mappingForContext:(RKObjectMappingProviderContext)context {
|
||||
id contextValue = [self valueForContext:context];
|
||||
if ([contextValue isEqual:[NSNull null]]) return nil;
|
||||
Protocol *protocol = @protocol(RKObjectMappingDefinition);
|
||||
NSAssert([contextValue conformsToProtocol:protocol], @"Storage type mismatch for context %d: expected a %@, got %@.", context, protocol, [contextValue class]);
|
||||
Class class = [RKObjectMappingDefinition class];
|
||||
NSAssert([contextValue isKindOfClass:class], @"Storage type mismatch for context %d: expected a %@, got %@.", context, class, [contextValue class]);
|
||||
return contextValue;
|
||||
}
|
||||
|
||||
@@ -184,7 +184,7 @@
|
||||
return [NSArray arrayWithArray:contextValue];
|
||||
}
|
||||
|
||||
- (void)addMapping:(id<RKObjectMappingDefinition>)mapping context:(RKObjectMappingProviderContext)context {
|
||||
- (void)addMapping:(RKObjectMappingDefinition *)mapping context:(RKObjectMappingProviderContext)context {
|
||||
NSMutableArray *contextValue = [self valueForContext:context];
|
||||
if (contextValue == nil) {
|
||||
contextValue = [NSMutableArray arrayWithCapacity:1];
|
||||
@@ -194,7 +194,7 @@
|
||||
[contextValue addObject:mapping];
|
||||
}
|
||||
|
||||
- (void)removeMapping:(id<RKObjectMappingDefinition>)mapping context:(RKObjectMappingProviderContext)context {
|
||||
- (void)removeMapping:(RKObjectMappingDefinition *)mapping context:(RKObjectMappingProviderContext)context {
|
||||
NSMutableArray *contextValue = [self valueForContext:context];
|
||||
NSAssert(contextValue, @"Attempted to remove mapping from undefined context: %d", context);
|
||||
[self assertStorageForContext:context isKindOfClass:[NSArray class]];
|
||||
@@ -202,14 +202,14 @@
|
||||
[contextValue removeObject:mapping];
|
||||
}
|
||||
|
||||
- (id<RKObjectMappingDefinition>)mappingForKeyPath:(NSString *)keyPath context:(RKObjectMappingProviderContext)context {
|
||||
- (RKObjectMappingDefinition *)mappingForKeyPath:(NSString *)keyPath context:(RKObjectMappingProviderContext)context {
|
||||
NSMutableDictionary *contextValue = [self valueForContext:context];
|
||||
NSAssert(contextValue, @"Attempted to retrieve mapping from undefined context: %d", context);
|
||||
[self assertStorageForContext:context isKindOfClass:[NSDictionary class]];
|
||||
return [contextValue valueForKey:keyPath];
|
||||
}
|
||||
|
||||
- (void)setMapping:(id<RKObjectMappingDefinition>)mapping forKeyPath:(NSString *)keyPath context:(RKObjectMappingProviderContext)context {
|
||||
- (void)setMapping:(RKObjectMappingDefinition *)mapping forKeyPath:(NSString *)keyPath context:(RKObjectMappingProviderContext)context {
|
||||
NSMutableDictionary *contextValue = [self valueForContext:context];
|
||||
if (contextValue == nil) {
|
||||
contextValue = [NSMutableDictionary dictionary];
|
||||
@@ -225,7 +225,7 @@
|
||||
[contextValue removeObjectForKey:keyPath];
|
||||
}
|
||||
|
||||
- (void)setMapping:(id<RKObjectMappingDefinition>)mapping forPattern:(NSString *)pattern atIndex:(NSUInteger)index context:(RKObjectMappingProviderContext)context {
|
||||
- (void)setMapping:(RKObjectMappingDefinition *)mapping forPattern:(NSString *)pattern atIndex:(NSUInteger)index context:(RKObjectMappingProviderContext)context {
|
||||
RKOrderedDictionary *contextValue = [self valueForContext:context];
|
||||
if (contextValue == nil) {
|
||||
contextValue = [RKOrderedDictionary dictionary];
|
||||
@@ -235,7 +235,7 @@
|
||||
[contextValue insertObject:mapping forKey:pattern atIndex:index];
|
||||
}
|
||||
|
||||
- (void)setMapping:(id<RKObjectMappingDefinition>)mapping forPattern:(NSString *)pattern context:(RKObjectMappingProviderContext)context {
|
||||
- (void)setMapping:(RKObjectMappingDefinition *)mapping forPattern:(NSString *)pattern context:(RKObjectMappingProviderContext)context {
|
||||
RKOrderedDictionary *contextValue = [self valueForContext:context];
|
||||
if (contextValue == nil) {
|
||||
contextValue = [RKOrderedDictionary dictionary];
|
||||
@@ -245,7 +245,7 @@
|
||||
[contextValue setObject:mapping forKey:pattern];
|
||||
}
|
||||
|
||||
- (id<RKObjectMappingDefinition>)mappingForPatternMatchingString:(NSString *)string context:(RKObjectMappingProviderContext)context {
|
||||
- (RKObjectMappingDefinition *)mappingForPatternMatchingString:(NSString *)string context:(RKObjectMappingProviderContext)context {
|
||||
RKOrderedDictionary *contextValue = [self valueForContext:context];
|
||||
NSAssert(contextValue, @"Attempted to retrieve mapping from undefined context: %d", context);
|
||||
for (NSString *pattern in contextValue) {
|
||||
|
||||
@@ -25,15 +25,15 @@
|
||||
@class RKObjectmapping;
|
||||
|
||||
@interface RKObjectRelationshipMapping : RKObjectAttributeMapping {
|
||||
id<RKObjectMappingDefinition> _mapping;
|
||||
RKObjectMappingDefinition * _mapping;
|
||||
BOOL _reversible;
|
||||
}
|
||||
|
||||
@property (nonatomic, retain) id<RKObjectMappingDefinition> mapping;
|
||||
@property (nonatomic, retain) RKObjectMappingDefinition * mapping;
|
||||
@property (nonatomic, assign) BOOL reversible;
|
||||
|
||||
+ (RKObjectRelationshipMapping*)mappingFromKeyPath:(NSString*)sourceKeyPath toKeyPath:(NSString*)destinationKeyPath withMapping:(id<RKObjectMappingDefinition>)objectOrDynamicMapping;
|
||||
+ (RKObjectRelationshipMapping*)mappingFromKeyPath:(NSString*)sourceKeyPath toKeyPath:(NSString*)destinationKeyPath withMapping:(RKObjectMappingDefinition *)objectOrDynamicMapping;
|
||||
|
||||
+ (RKObjectRelationshipMapping*)mappingFromKeyPath:(NSString*)sourceKeyPath toKeyPath:(NSString*)destinationKeyPath withMapping:(id<RKObjectMappingDefinition>)objectOrDynamicMapping reversible:(BOOL)reversible;
|
||||
+ (RKObjectRelationshipMapping*)mappingFromKeyPath:(NSString*)sourceKeyPath toKeyPath:(NSString*)destinationKeyPath withMapping:(RKObjectMappingDefinition *)objectOrDynamicMapping reversible:(BOOL)reversible;
|
||||
|
||||
@end
|
||||
|
||||
@@ -25,14 +25,14 @@
|
||||
@synthesize mapping = _mapping;
|
||||
@synthesize reversible = _reversible;
|
||||
|
||||
+ (RKObjectRelationshipMapping*)mappingFromKeyPath:(NSString*)sourceKeyPath toKeyPath:(NSString*)destinationKeyPath withMapping:(id<RKObjectMappingDefinition>)objectOrDynamicMapping reversible:(BOOL)reversible {
|
||||
+ (RKObjectRelationshipMapping*)mappingFromKeyPath:(NSString*)sourceKeyPath toKeyPath:(NSString*)destinationKeyPath withMapping:(RKObjectMappingDefinition *)objectOrDynamicMapping reversible:(BOOL)reversible {
|
||||
RKObjectRelationshipMapping* relationshipMapping = (RKObjectRelationshipMapping*) [self mappingFromKeyPath:sourceKeyPath toKeyPath:destinationKeyPath];
|
||||
relationshipMapping.reversible = reversible;
|
||||
relationshipMapping.mapping = objectOrDynamicMapping;
|
||||
return relationshipMapping;
|
||||
}
|
||||
|
||||
+ (RKObjectRelationshipMapping*)mappingFromKeyPath:(NSString*)sourceKeyPath toKeyPath:(NSString*)destinationKeyPath withMapping:(id<RKObjectMappingDefinition>)objectOrDynamicMapping {
|
||||
+ (RKObjectRelationshipMapping*)mappingFromKeyPath:(NSString*)sourceKeyPath toKeyPath:(NSString*)destinationKeyPath withMapping:(RKObjectMappingDefinition *)objectOrDynamicMapping {
|
||||
return [self mappingFromKeyPath:sourceKeyPath toKeyPath:destinationKeyPath withMapping:objectOrDynamicMapping reversible:YES];
|
||||
}
|
||||
|
||||
|
||||
@@ -19,7 +19,10 @@
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
#if TARGET_OS_IPHONE
|
||||
#import <UIKit/UIImage.h>
|
||||
#endif
|
||||
|
||||
/**
|
||||
Provides convenience methods for accessing data in resources
|
||||
@@ -55,6 +58,7 @@
|
||||
*/
|
||||
- (NSString *)stringWithContentsOfResource:(NSString *)name withExtension:(NSString *)extension encoding:(NSStringEncoding)encoding;
|
||||
|
||||
#if TARGET_OS_IPHONE
|
||||
/**
|
||||
Creates and returns an image object by loading the image data from the resource identified by the specified name and file extension.
|
||||
|
||||
@@ -63,6 +67,7 @@
|
||||
@return A new image object for the specified file, or nil if the method could not initialize the image from the specified file.
|
||||
*/
|
||||
- (UIImage *)imageWithContentsOfResource:(NSString *)name withExtension:(NSString *)extension;
|
||||
#endif
|
||||
|
||||
/**
|
||||
Creates and returns an object representation of the data from the resource identified by the specified name and file extension by reading the
|
||||
|
||||
@@ -61,6 +61,7 @@
|
||||
return fixtureData;
|
||||
}
|
||||
|
||||
#if TARGET_OS_IPHONE
|
||||
- (UIImage *)imageWithContentsOfResource:(NSString *)name withExtension:(NSString *)extension {
|
||||
NSString *resourcePath = [self pathForResource:name ofType:extension];
|
||||
if (! resourcePath) {
|
||||
@@ -70,6 +71,7 @@
|
||||
|
||||
return [UIImage imageWithContentsOfFile:resourcePath];
|
||||
}
|
||||
#endif
|
||||
|
||||
- (id)parsedObjectWithContentsOfResource:(NSString *)name withExtension:(NSString *)extension {
|
||||
NSError* error = nil;
|
||||
|
||||
@@ -19,7 +19,9 @@
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import <UIKit/UIImage.h>
|
||||
#if TARGET_OS_IPHONE
|
||||
#import <UIKit/UIKit.h>
|
||||
#endif
|
||||
|
||||
/**
|
||||
Provides a static method API for conveniently accessing fixture data
|
||||
@@ -43,6 +45,7 @@
|
||||
*/
|
||||
+ (void)setFixtureBundle:(NSBundle *)bundle;
|
||||
|
||||
#if TARGET_OS_IPHONE
|
||||
/**
|
||||
Creates and returns an image object by loading the image data from the fixture identified by the specified file name.
|
||||
|
||||
@@ -50,6 +53,7 @@
|
||||
@return A new image object for the specified fixture, or nil if the method could not initialize the image from the specified file.
|
||||
*/
|
||||
+ (UIImage *)imageWithContentsOfFixture:(NSString *)fixtureName;
|
||||
#endif
|
||||
|
||||
/**
|
||||
Creates and returns a string object by reading data from the fixture identified by the specified file name using UTF-8 encoding.
|
||||
|
||||
@@ -35,9 +35,11 @@ static NSBundle *fixtureBundle = nil;
|
||||
fixtureBundle = bundle;
|
||||
}
|
||||
|
||||
#if TARGET_OS_IPHONE
|
||||
+ (UIImage *)imageWithContentsOfFixture:(NSString *)fixtureName {
|
||||
return [fixtureBundle imageWithContentsOfResource:fixtureName withExtension:nil];
|
||||
}
|
||||
#endif
|
||||
|
||||
+ (NSString *)stringWithContentsOfFixture:(NSString *)fixtureName {
|
||||
return [fixtureBundle stringWithContentsOfResource:fixtureName withExtension:nil encoding:NSUTF8StringEncoding];
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
//
|
||||
|
||||
#ifdef TARGET_OS_IPHONE
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
#import "RKTableSection.h"
|
||||
#import "RKTableViewCellMappings.h"
|
||||
|
||||
Reference in New Issue
Block a user