mirror of
https://github.com/zhigang1992/RestKit.git
synced 2026-04-12 21:43:22 +08:00
Trailing whitespace cleanup from files in the Code directory.
Used the following command from within the Code dir: git ls-files *.m *.h *.json | xargs /usr/bin/sed -i '' -E 's/[[:space:]]*$//'
This commit is contained in:
@@ -29,29 +29,29 @@
|
||||
/**
|
||||
Creates and returns a new attribute mapping specifying that data is to be read from a given key path on a source object
|
||||
and set to a given key path on a destination object.
|
||||
|
||||
|
||||
Attribute mappings define transformation between key paths in the source and destination object beings mapped. In the simplest
|
||||
case, an attribute mapping may simply specify that data from one object is to be copied to another. A common example of this
|
||||
type of transformation is copying the `name` key from a JSON payload onto a local object. In this case, the source and
|
||||
type of transformation is copying the `name` key from a JSON payload onto a local object. In this case, the source and
|
||||
destination key paths are identical, as are the source and destination types (NSString), so a simple get and set operation
|
||||
has been defined.
|
||||
|
||||
has been defined.
|
||||
|
||||
The next most common use-case is the transformation of identical data between two different key paths in the
|
||||
source and destination objects. This is typically encountered when you wish to transform inbound data to conform with the naming
|
||||
conventions of the platform or the data model of your application. An example of this type of transformation would be from the
|
||||
conventions of the platform or the data model of your application. An example of this type of transformation would be from the
|
||||
source key path of `first_name` to the destination key path of `firstName`. In this transformation, the key paths have diverged
|
||||
but both sides of the mapping correspond to NSString properties.
|
||||
|
||||
|
||||
The final type of transformation to be specified via an attribute mapping involves the transformation between types in the mapping.
|
||||
By far, the most common example of this use-case is the transformation of a inbound string or numeric property into a date on
|
||||
the target object. For example, consider a backend system that returns the creation date of a piece of content in a JSON payload.
|
||||
This data might be returned in JSON as `{"created_on": "2012-08-27"}`. In a given application, the developer may wish to model this
|
||||
data as an NSDate `createdOn` property on the target object. An attribute mapping to support this mapping would specify a source
|
||||
data as an NSDate `createdOn` property on the target object. An attribute mapping to support this mapping would specify a source
|
||||
key path of `created_on` and a destination key path of `createdOn`. On the destination object, the `createdOn` property would be defined
|
||||
as `@property (nonatomic, strong) NSDate *createdOn;`. At mapping time, the mapping operation inspects the type of the content being
|
||||
mapped and attempts to transform the source content into the type of the desination property specified by the mapping. In this case,
|
||||
mapped and attempts to transform the source content into the type of the desination property specified by the mapping. In this case,
|
||||
an NSDateFormatter object would be used to process the inbound NSString into an outbound NSDate object.
|
||||
|
||||
|
||||
@param sourceKeyPath The key path on the source object from which to read the data being mapped.
|
||||
@param destinationKeyPath The key path on the destination object on which to set the mapped data.
|
||||
@return A newly created attribute mapping object that is ready to be added to an object mapping.
|
||||
|
||||
@@ -33,25 +33,25 @@ typedef id(^RKObjectConnectionBlock)(RKConnectionMapping *mapping, id source);
|
||||
appropriate target object(s). It does this by using the value of the object's
|
||||
fromKeyPath attribute to query instances of the target entity that have the
|
||||
same value in their toKeyPath attribute.
|
||||
|
||||
|
||||
Note that connectRelationship runs *after* an object's attributes have been
|
||||
mapped and is dependent upon the results of those mappings. Also, connectRelationship
|
||||
will never create a new object - it simply looks up existing objects. In effect,
|
||||
connectRelationship allows foreign key relationships between managed objects
|
||||
to be automatically maintained from the server to the underlying Core Data object graph.
|
||||
|
||||
|
||||
For example, given a Project object associated with a User, where the 'user' relationship is
|
||||
specified by a userID property on the managed object:
|
||||
|
||||
|
||||
[mapping connectRelationship:@"user" withMapping:userMapping fromKeyPath:@"userId" toKeyPath:@"id"];
|
||||
|
||||
|
||||
Will hydrate the 'user' association on the managed object with the object
|
||||
in the local object graph having the primary key specified in the managed object's
|
||||
userID property.
|
||||
|
||||
|
||||
You can also do the reverse. Given a User object associated with a Project, with a
|
||||
'project' relationship:
|
||||
|
||||
|
||||
[mapping connectRelationship:@"project" fromKeyPath:@"id" toKeyPath:@"userId" withMapping:projectMapping];
|
||||
*/
|
||||
//- (void)connectRelationship:(NSString *)relationshipName fromKeyPath:(NSString *)sourceKeyPath toKeyPath:(NSString *)destinationKeyPath withMapping:(RKMapping *)objectOrDynamicMapping DEPRECATED_ATTRIBUTE;
|
||||
@@ -59,17 +59,17 @@ typedef id(^RKObjectConnectionBlock)(RKConnectionMapping *mapping, id source);
|
||||
/**
|
||||
Conditionally connect a relationship of the object being mapped when the object being mapped has
|
||||
keyPath equal to a specified value.
|
||||
|
||||
|
||||
For example, given a Project object associated with a User, where the 'admin' relationship is
|
||||
specified by a adminID property on the managed object:
|
||||
|
||||
|
||||
[mapping connectRelationship:@"admin" fromKeyPath:@"adminId" toKeyPath:@"id" withMapping:userMapping whenValueOfKeyPath:@"userType" isEqualTo:@"Admin"];
|
||||
|
||||
|
||||
Will hydrate the 'admin' association on the managed object with the object
|
||||
in the local object graph having the primary key specified in the managed object's
|
||||
userID property. Note that this connection will only occur when the Product's 'userType'
|
||||
property equals 'Admin'. In cases where no match occurs, the relationship connection is skipped.
|
||||
|
||||
|
||||
@see connectRelationship:withObjectForPrimaryKeyAttribute:
|
||||
*/
|
||||
// - (void)connectRelationship:(NSString *)relationshipName fromKeyPath:(NSString *)sourceKeyPath toKeyPath:(NSString *)destinationKeyPath withMapping:(RKMapping *)objectOrDynamicMapping whenValueOfKeyPath:(NSString *)keyPath isEqualTo:(id)value DEPRECATED_ATTRIBUTE;
|
||||
@@ -77,19 +77,19 @@ typedef id(^RKObjectConnectionBlock)(RKConnectionMapping *mapping, id source);
|
||||
Conditionally connect a relationship of the object being mapped when the object being mapped has
|
||||
block evaluate to YES. This variant is useful in cases where you want to execute an arbitrary
|
||||
block to determine whether or not to connect a relationship.
|
||||
|
||||
|
||||
For example, given a Project object associated with a User, where the 'admin' relationship is
|
||||
specified by a adminID property on the managed object:
|
||||
|
||||
|
||||
[mapping connectRelationship:@"admin" fromKeyPath:@"adminId" toKeyPath:@"adminID" withMapping:userMapping usingEvaluationBlock:^(id data) {
|
||||
return [User isAuthenticated];
|
||||
}];
|
||||
|
||||
|
||||
Will hydrate the 'admin' association on the managed object with the object
|
||||
in the local object graph having the primary key specified in the managed object's
|
||||
userID property. Note that this connection will only occur when the provided block evalutes to YES.
|
||||
In cases where no match occurs, the relationship connection is skipped.
|
||||
|
||||
|
||||
@see connectRelationship:withObjectForPrimaryKeyAttribute:
|
||||
*/
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@ RKRequestMethod RKRequestMethodFromString(NSString *);
|
||||
|
||||
/**
|
||||
The HTTP status code classes
|
||||
|
||||
|
||||
See http://tools.ietf.org/html/rfc2616#section-10
|
||||
*/
|
||||
enum {
|
||||
@@ -40,7 +40,7 @@ typedef NSUInteger RKStatusCodeClass;
|
||||
|
||||
/**
|
||||
Creates a new range covering the status codes in the given class.
|
||||
|
||||
|
||||
@param statusCodeClass The status code class to create a range covering.
|
||||
@return A new range covering the status codes in the given class.
|
||||
*/
|
||||
@@ -48,7 +48,7 @@ NSRange RKStatusCodeRangeForClass(RKStatusCodeClass statusCodeClass);
|
||||
|
||||
/**
|
||||
Creates a new index set covering the status codes in the given class.
|
||||
|
||||
|
||||
@param statusCodeClass The status code class to create an index set covering.
|
||||
@return A new index set covering the status codes in the given class.
|
||||
*/
|
||||
|
||||
@@ -26,31 +26,31 @@ NSString *RKStringFromRequestMethod(RKRequestMethod method)
|
||||
case RKRequestMethodGET:
|
||||
return @"GET";
|
||||
break;
|
||||
|
||||
|
||||
case RKRequestMethodPOST:
|
||||
return @"POST";
|
||||
break;
|
||||
|
||||
|
||||
case RKRequestMethodPUT:
|
||||
return @"PUT";
|
||||
break;
|
||||
|
||||
|
||||
case RKRequestMethodPATCH:
|
||||
return @"PATCH";
|
||||
break;
|
||||
|
||||
|
||||
case RKRequestMethodDELETE:
|
||||
return @"DELETE";
|
||||
break;
|
||||
|
||||
|
||||
case RKRequestMethodHEAD:
|
||||
return @"HEAD";
|
||||
break;
|
||||
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
return nil;
|
||||
}
|
||||
|
||||
@@ -69,6 +69,6 @@ RKRequestMethod RKRequestMethodFromString(NSString *methodName)
|
||||
} else if ([methodName isEqualToString:@"PATCH"]) {
|
||||
return RKRequestMethodPATCH;
|
||||
}
|
||||
|
||||
|
||||
return RKRequestMethodInvalid;
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ typedef NSFetchRequest * (^RKFetchRequestBlock)(NSURL *URL);
|
||||
/**
|
||||
A Boolean value that determines if the receiver will delete orphaned objects upon
|
||||
completion of the operation.
|
||||
|
||||
|
||||
**Default**: NO
|
||||
*/
|
||||
@property (nonatomic, assign) BOOL deletesOrphanedObjects;
|
||||
|
||||
@@ -148,7 +148,7 @@
|
||||
RKLogDebug(@"Skipping deletion of orphaned objects: deletesOrphanedObjects=NO");
|
||||
return YES;
|
||||
}
|
||||
|
||||
|
||||
if (! [[self.requestOperation.request.HTTPMethod uppercaseString] isEqualToString:@"GET"]) {
|
||||
RKLogDebug(@"Skipping cleanup of objects via managed object cache: only used for GET requests.");
|
||||
return YES;
|
||||
|
||||
@@ -85,13 +85,13 @@
|
||||
|
||||
/**
|
||||
Tells the delegate that the mapping operation has selected a concrete object mapping with which to map the source object.
|
||||
|
||||
|
||||
Only sent if the receiver was initialized with an instance of RKDynamicMapping as the mapping.
|
||||
|
||||
|
||||
@param operation The mapping operation.
|
||||
@param objectMapping The concrete object mapping with which to perform the mapping.
|
||||
@param dynamicMapping The dynamic source mapping from which the object mapping was determined.
|
||||
|
||||
|
||||
@since 0.11.0
|
||||
*/
|
||||
- (void)mappingOperation:(RKMappingOperation *)operation didSelectObjectMapping:(RKObjectMapping *)objectMapping forDynamicMapping:(RKDynamicMapping *)dynamicMapping;
|
||||
@@ -121,7 +121,7 @@
|
||||
|
||||
/**
|
||||
The mapping defining how values contained in the source object should be transformed to the destination object via key-value coding.
|
||||
|
||||
|
||||
Will either be an instance of RKObjectMapping or RKDynamicMapping.
|
||||
*/
|
||||
@property (nonatomic, strong, readonly) RKMapping *mapping;
|
||||
|
||||
@@ -643,12 +643,12 @@ BOOL RKObjectIsValueEqualToValue(id sourceValue, id destinationValue) {
|
||||
{
|
||||
RKLogDebug(@"Starting mapping operation...");
|
||||
RKLogTrace(@"Performing mapping operation: %@", self);
|
||||
|
||||
|
||||
// Determine the concrete mapping if we were initialized with a dynamic mapping
|
||||
if ([self.mapping isKindOfClass:[RKDynamicMapping class]]) {
|
||||
self.objectMapping = [(RKDynamicMapping *)self.mapping objectMappingForDictionary:self.sourceObject];
|
||||
RKLogDebug(@"RKObjectMappingOperation was initialized with a dynamic mapping. Determined concrete mapping = %@", self.objectMapping);
|
||||
|
||||
|
||||
if ([self.delegate respondsToSelector:@selector(mappingOperation:didSelectObjectMapping:forDynamicMapping:)]) {
|
||||
[self.delegate mappingOperation:self didSelectObjectMapping:self.objectMapping forDynamicMapping:(RKDynamicMapping *)self.mapping];
|
||||
}
|
||||
@@ -662,7 +662,7 @@ BOOL RKObjectIsValueEqualToValue(id sourceValue, id destinationValue) {
|
||||
BOOL mappedRelationships = [self applyRelationshipMappings];
|
||||
if ((mappedAttributes || mappedRelationships) && _validationError == nil) {
|
||||
RKLogDebug(@"Finished mapping operation successfully...");
|
||||
|
||||
|
||||
if ([self.dataSource respondsToSelector:@selector(commitChangesForMappingOperation:)]) {
|
||||
[self.dataSource commitChangesForMappingOperation:self];
|
||||
}
|
||||
|
||||
@@ -75,14 +75,14 @@ static NSOperationQueue *defaultMappingQueue = nil;
|
||||
if (self) {
|
||||
self.HTTPClient = client;
|
||||
[self.HTTPClient registerHTTPOperationClass:[RKHTTPRequestOperation class]];
|
||||
|
||||
|
||||
self.router = [[RKRouter alloc] initWithBaseURL:client.baseURL];
|
||||
self.acceptMIMEType = RKMIMETypeJSON;
|
||||
self.operationQueue = [NSOperationQueue new];
|
||||
self.mutableRequestDescriptors = [NSMutableArray new];
|
||||
self.mutableResponseDescriptors = [NSMutableArray new];
|
||||
self.mutableFetchRequestBlocks = [NSMutableArray new];
|
||||
|
||||
|
||||
self.serializationMIMEType = RKMIMETypeFormURLEncoded;
|
||||
self.mappingQueue = [RKObjectManager defaultMappingQueue];
|
||||
|
||||
@@ -234,7 +234,7 @@ static NSOperationQueue *defaultMappingQueue = nil;
|
||||
} else {
|
||||
requestParameters = parameters;
|
||||
}
|
||||
|
||||
|
||||
return [self.HTTPClient requestWithMethod:stringMethod path:requestPath parameters:requestParameters];
|
||||
}
|
||||
|
||||
@@ -257,7 +257,7 @@ static NSOperationQueue *defaultMappingQueue = nil;
|
||||
} else {
|
||||
requestParameters = parameters;
|
||||
}
|
||||
|
||||
|
||||
return [self.HTTPClient multipartFormRequestWithMethod:stringMethod path:requestPath parameters:requestParameters constructingBodyWithBlock:block];
|
||||
}
|
||||
|
||||
@@ -300,7 +300,7 @@ static NSOperationQueue *defaultMappingQueue = nil;
|
||||
TODO: Test cases...
|
||||
1) Managed object
|
||||
2) Non managed object, request descriptors with entity
|
||||
|
||||
|
||||
Does it make sense to assume the main queue MOC here?
|
||||
*/
|
||||
- (id)objectRequestOperationWithObject:(id)object method:(RKRequestMethod)method path:(NSString *)path parameters:(NSDictionary *)parameters
|
||||
@@ -314,7 +314,7 @@ static NSOperationQueue *defaultMappingQueue = nil;
|
||||
RKLogInfo(@"Asked to perform object request with NSManagedObject with temporary object ID: Obtaining permanent ID before proceeding.");
|
||||
__block BOOL _blockSuccess;
|
||||
__block NSError *_blockError;
|
||||
|
||||
|
||||
[[object managedObjectContext] performBlockAndWait:^{
|
||||
_blockSuccess = [[object managedObjectContext] obtainPermanentIDsForObjects:@[object] error:&_blockError];
|
||||
}];
|
||||
|
||||
@@ -49,7 +49,7 @@ NSString * const RKMappingErrorKeyPathErrorKey = @"keyPath";
|
||||
self.mappingErrors = [NSMutableArray new];
|
||||
self.mappingOperationDataSource = [RKObjectMappingOperationDataSource new];
|
||||
}
|
||||
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
@@ -238,7 +238,7 @@ NSString * const RKMappingErrorKeyPathErrorKey = @"keyPath";
|
||||
{
|
||||
NSAssert([mapping isKindOfClass:[RKMapping class]], @"Expected an RKMapping object");
|
||||
NSAssert(self.mappingOperationDataSource, @"Cannot find or instantiate objects without a data source");
|
||||
|
||||
|
||||
RKObjectMapping *objectMapping = nil;
|
||||
if ([mapping isKindOfClass:[RKDynamicMapping class]]) {
|
||||
objectMapping = [(RKDynamicMapping *)mapping objectMappingForDictionary:mappableData];
|
||||
|
||||
@@ -144,7 +144,7 @@ relationship. Relationships are processed using an object mapping as well.
|
||||
|
||||
/**
|
||||
Removes an instance of an attribute or relationship mapping from the object mapping
|
||||
|
||||
|
||||
@param attributeOrRelationshipMapping The attribute or relationship mapping to remove
|
||||
*/
|
||||
- (void)removePropertyMapping:(RKPropertyMapping *)propertyMapping;
|
||||
@@ -154,7 +154,7 @@ relationship. Relationships are processed using an object mapping as well.
|
||||
/**
|
||||
Adds attribute mappings from a given dictionary wherein the keys represent the source key path
|
||||
and the values represent the names of the target attributes on the destination object.
|
||||
|
||||
|
||||
@param keyPathToAttributeNames A dictionary keyed by source key to destination attribute name.
|
||||
*/
|
||||
- (void)addAttributeMappingsFromDictionary:(NSDictionary *)keyPathToAttributeNames;
|
||||
|
||||
@@ -41,11 +41,11 @@
|
||||
|
||||
/**
|
||||
Compares the receiving property mapping to another property mapping.
|
||||
|
||||
|
||||
Two property mappings are equal if they are of the same type (i.e. an attribute or a
|
||||
relationship mapping) and specify a mapping from the same source key path to the
|
||||
relationship mapping) and specify a mapping from the same source key path to the
|
||||
same destination key path.
|
||||
|
||||
|
||||
@param otherMapping The property mapping object with which to compare the receiver.
|
||||
@return YES if otherMapping specifies the same mapping as the receiver, otherwise NO.
|
||||
*/
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
{
|
||||
NSParameterAssert(mapping);
|
||||
NSParameterAssert(objectClass);
|
||||
|
||||
|
||||
RKRequestDescriptor *requestDescriptor = [self new];
|
||||
requestDescriptor.mapping = mapping;
|
||||
requestDescriptor.objectClass = objectClass;
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
// Cloned from AFStringFromIndexSet -- method should be non-static for reuse
|
||||
static NSString * RKStringFromIndexSet(NSIndexSet *indexSet) {
|
||||
NSMutableString *string = [NSMutableString string];
|
||||
|
||||
|
||||
NSRange range = NSMakeRange([indexSet firstIndex], 1);
|
||||
while (range.location != NSNotFound) {
|
||||
NSUInteger nextIndex = [indexSet indexGreaterThanIndex:range.location];
|
||||
@@ -32,11 +32,11 @@ static NSString * RKStringFromIndexSet(NSIndexSet *indexSet) {
|
||||
range.length++;
|
||||
nextIndex = [indexSet indexGreaterThanIndex:nextIndex];
|
||||
}
|
||||
|
||||
|
||||
if (string.length) {
|
||||
[string appendString:@","];
|
||||
}
|
||||
|
||||
|
||||
if (range.length == 1) {
|
||||
[string appendFormat:@"%u", range.location];
|
||||
} else {
|
||||
@@ -44,11 +44,11 @@ static NSString * RKStringFromIndexSet(NSIndexSet *indexSet) {
|
||||
NSUInteger lastIndex = firstIndex + range.length - 1;
|
||||
[string appendFormat:@"%u-%u", firstIndex, lastIndex];
|
||||
}
|
||||
|
||||
|
||||
range.location = nextIndex;
|
||||
range.length = 1;
|
||||
}
|
||||
|
||||
|
||||
return string;
|
||||
}
|
||||
|
||||
@@ -67,13 +67,13 @@ static NSString * RKStringFromIndexSet(NSIndexSet *indexSet) {
|
||||
statusCodes:(NSIndexSet *)statusCodes
|
||||
{
|
||||
NSParameterAssert(mapping);
|
||||
|
||||
|
||||
RKResponseDescriptor *mappingDescriptor = [self new];
|
||||
mappingDescriptor.mapping = mapping;
|
||||
mappingDescriptor.pathPattern = pathPattern;
|
||||
mappingDescriptor.keyPath = keyPath;
|
||||
mappingDescriptor.statusCodes = statusCodes;
|
||||
|
||||
|
||||
return mappingDescriptor;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user