mirror of
https://github.com/zhigang1992/RestKit.git
synced 2026-04-22 20:18:53 +08:00
Placing opening braces on a new line for methods to match Apple convention. Refs #614
Used uncrustify's "nl_fdef_brace = add" option to detect issues.
This commit is contained in:
@@ -61,11 +61,13 @@
|
||||
@dynamic loading;
|
||||
@dynamic response;
|
||||
|
||||
+ (id)loaderWithURL:(RKURL *)URL mappingProvider:(RKObjectMappingProvider *)mappingProvider {
|
||||
+ (id)loaderWithURL:(RKURL *)URL mappingProvider:(RKObjectMappingProvider *)mappingProvider
|
||||
{
|
||||
return [[[self alloc] initWithURL:URL mappingProvider:mappingProvider] autorelease];
|
||||
}
|
||||
|
||||
- (id)initWithURL:(RKURL *)URL mappingProvider:(RKObjectMappingProvider *)mappingProvider {
|
||||
- (id)initWithURL:(RKURL *)URL mappingProvider:(RKObjectMappingProvider *)mappingProvider
|
||||
{
|
||||
self = [super initWithURL:URL];
|
||||
if (self) {
|
||||
_mappingProvider = [mappingProvider retain];
|
||||
@@ -75,7 +77,8 @@
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)dealloc {
|
||||
- (void)dealloc
|
||||
{
|
||||
[_mappingProvider release];
|
||||
_mappingProvider = nil;
|
||||
[_sourceObject release];
|
||||
@@ -102,13 +105,15 @@
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
- (void)reset {
|
||||
- (void)reset
|
||||
{
|
||||
[super reset];
|
||||
[_result release];
|
||||
_result = nil;
|
||||
}
|
||||
|
||||
- (void)informDelegateOfError:(NSError *)error {
|
||||
- (void)informDelegateOfError:(NSError *)error
|
||||
{
|
||||
[(NSObject<RKObjectLoaderDelegate>*)_delegate objectLoader:self didFailWithError:error];
|
||||
|
||||
if (self.onDidFailWithError) {
|
||||
@@ -120,7 +125,8 @@
|
||||
|
||||
// NOTE: This method is significant because the notifications posted are used by
|
||||
// RKRequestQueue to remove requests from the queue. All requests need to be finalized.
|
||||
- (void)finalizeLoad:(BOOL)successful {
|
||||
- (void)finalizeLoad:(BOOL)successful
|
||||
{
|
||||
self.loading = NO;
|
||||
self.loaded = successful;
|
||||
|
||||
@@ -133,7 +139,8 @@
|
||||
}
|
||||
|
||||
// Invoked on the main thread. Inform the delegate.
|
||||
- (void)informDelegateOfObjectLoadWithResultDictionary:(NSDictionary*)resultDictionary {
|
||||
- (void)informDelegateOfObjectLoadWithResultDictionary:(NSDictionary*)resultDictionary
|
||||
{
|
||||
NSAssert([NSThread isMainThread], @"RKObjectLoaderDelegate callbacks must occur on the main thread");
|
||||
|
||||
RKObjectMappingResult* result = [RKObjectMappingResult mappingResultWithDictionary:resultDictionary];
|
||||
@@ -175,14 +182,16 @@
|
||||
at thread boundaries.
|
||||
@protected
|
||||
*/
|
||||
- (void)processMappingResult:(RKObjectMappingResult*)result {
|
||||
- (void)processMappingResult:(RKObjectMappingResult*)result
|
||||
{
|
||||
NSAssert(_sentSynchronously || ![NSThread isMainThread], @"Mapping result processing should occur on a background thread");
|
||||
[self performSelectorOnMainThread:@selector(informDelegateOfObjectLoadWithResultDictionary:) withObject:[result asDictionary] waitUntilDone:YES];
|
||||
}
|
||||
|
||||
#pragma mark - Response Object Mapping
|
||||
|
||||
- (RKObjectMappingResult*)mapResponseWithMappingProvider:(RKObjectMappingProvider*)mappingProvider toObject:(id)targetObject inContext:(RKObjectMappingProviderContext)context error:(NSError**)error {
|
||||
- (RKObjectMappingResult*)mapResponseWithMappingProvider:(RKObjectMappingProvider*)mappingProvider toObject:(id)targetObject inContext:(RKObjectMappingProviderContext)context error:(NSError**)error
|
||||
{
|
||||
id<RKParser> parser = [[RKParserRegistry sharedRegistry] parserForMIMEType:self.response.MIMEType];
|
||||
NSAssert1(parser, @"Cannot perform object load without a parser for MIME Type '%@'", self.response.MIMEType);
|
||||
|
||||
@@ -232,7 +241,8 @@
|
||||
return result;
|
||||
}
|
||||
|
||||
- (RKObjectMappingDefinition *)configuredObjectMapping {
|
||||
- (RKObjectMappingDefinition *)configuredObjectMapping
|
||||
{
|
||||
if (self.objectMapping) {
|
||||
return self.objectMapping;
|
||||
}
|
||||
@@ -240,7 +250,8 @@
|
||||
return [self.mappingProvider objectMappingForResourcePath:self.resourcePath];
|
||||
}
|
||||
|
||||
- (RKObjectMappingResult*)performMapping:(NSError**)error {
|
||||
- (RKObjectMappingResult*)performMapping:(NSError**)error
|
||||
{
|
||||
NSAssert(_sentSynchronously || ![NSThread isMainThread], @"Mapping should occur on a background thread");
|
||||
|
||||
RKObjectMappingProvider* mappingProvider;
|
||||
@@ -260,7 +271,8 @@
|
||||
return [self mapResponseWithMappingProvider:mappingProvider toObject:self.targetObject inContext:RKObjectMappingProviderContextObjectsByKeyPath error:error];
|
||||
}
|
||||
|
||||
- (void)performMappingInDispatchQueue {
|
||||
- (void)performMappingInDispatchQueue
|
||||
{
|
||||
NSAssert(self.mappingQueue, @"mappingQueue cannot be nil");
|
||||
dispatch_async(self.mappingQueue, ^{
|
||||
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
|
||||
@@ -279,7 +291,8 @@
|
||||
});
|
||||
}
|
||||
|
||||
- (BOOL)canParseMIMEType:(NSString*)MIMEType {
|
||||
- (BOOL)canParseMIMEType:(NSString*)MIMEType
|
||||
{
|
||||
if ([[RKParserRegistry sharedRegistry] parserForMIMEType:self.response.MIMEType]) {
|
||||
return YES;
|
||||
}
|
||||
@@ -288,7 +301,8 @@
|
||||
return NO;
|
||||
}
|
||||
|
||||
- (BOOL)isResponseMappable {
|
||||
- (BOOL)isResponseMappable
|
||||
{
|
||||
if ([self.response isServiceUnavailable]) {
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:RKServiceDidBecomeUnavailableNotification object:self];
|
||||
}
|
||||
@@ -334,7 +348,8 @@
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (void)handleResponseError {
|
||||
- (void)handleResponseError
|
||||
{
|
||||
// Since we are mapping what we know to be an error response, we don't want to map the result back onto our
|
||||
// target object
|
||||
NSError *error = nil;
|
||||
@@ -352,7 +367,8 @@
|
||||
#pragma mark - RKRequest & RKRequestDelegate methods
|
||||
|
||||
// Invoked just before request hits the network
|
||||
- (BOOL)prepareURLRequest {
|
||||
- (BOOL)prepareURLRequest
|
||||
{
|
||||
if ((self.sourceObject && self.params == nil) && (self.method == RKRequestMethodPOST || self.method == RKRequestMethodPUT)) {
|
||||
NSAssert(self.serializationMapping, @"You must provide a serialization mapping for objects of type '%@'", NSStringFromClass([self.sourceObject class]));
|
||||
RKLogDebug(@"POST or PUT request for source object %@, serializing to MIME Type %@ for transport...", self.sourceObject, self.serializationMIMEType);
|
||||
@@ -383,7 +399,8 @@
|
||||
return [super prepareURLRequest];
|
||||
}
|
||||
|
||||
- (void)didFailLoadWithError:(NSError *)error {
|
||||
- (void)didFailLoadWithError:(NSError *)error
|
||||
{
|
||||
NSParameterAssert(error);
|
||||
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
|
||||
|
||||
@@ -419,7 +436,8 @@
|
||||
}
|
||||
|
||||
// NOTE: We do NOT call super here. We are overloading the default behavior from RKRequest
|
||||
- (void)didFinishLoad:(RKResponse*)response {
|
||||
- (void)didFinishLoad:(RKResponse*)response
|
||||
{
|
||||
NSAssert([NSThread isMainThread], @"RKObjectLoaderDelegate callbacks must occur on the main thread");
|
||||
self.response = response;
|
||||
|
||||
@@ -464,7 +482,8 @@
|
||||
}
|
||||
}
|
||||
|
||||
- (void)setMappingQueue:(dispatch_queue_t)newMappingQueue {
|
||||
- (void)setMappingQueue:(dispatch_queue_t)newMappingQueue
|
||||
{
|
||||
if (_mappingQueue) {
|
||||
dispatch_release(_mappingQueue);
|
||||
_mappingQueue = nil;
|
||||
@@ -478,11 +497,13 @@
|
||||
|
||||
// Proxy the delegate property back to our superclass implementation. The object loader should
|
||||
// really not be a subclass of RKRequest.
|
||||
- (void)setDelegate:(id<RKObjectLoaderDelegate>)delegate {
|
||||
- (void)setDelegate:(id<RKObjectLoaderDelegate>)delegate
|
||||
{
|
||||
[super setDelegate:delegate];
|
||||
}
|
||||
|
||||
- (id<RKObjectLoaderDelegate>)delegate {
|
||||
- (id<RKObjectLoaderDelegate>)delegate
|
||||
{
|
||||
return (id<RKObjectLoaderDelegate>) [super delegate];
|
||||
}
|
||||
|
||||
@@ -490,11 +511,13 @@
|
||||
|
||||
@implementation RKObjectLoader (Deprecations)
|
||||
|
||||
+ (id)loaderWithResourcePath:(NSString*)resourcePath objectManager:(RKObjectManager*)objectManager delegate:(id<RKObjectLoaderDelegate>)delegate {
|
||||
+ (id)loaderWithResourcePath:(NSString*)resourcePath objectManager:(RKObjectManager*)objectManager delegate:(id<RKObjectLoaderDelegate>)delegate
|
||||
{
|
||||
return [[[self alloc] initWithResourcePath:resourcePath objectManager:objectManager delegate:delegate] autorelease];
|
||||
}
|
||||
|
||||
- (id)initWithResourcePath:(NSString*)resourcePath objectManager:(RKObjectManager*)objectManager delegate:(id<RKObjectLoaderDelegate>)theDelegate {
|
||||
- (id)initWithResourcePath:(NSString*)resourcePath objectManager:(RKObjectManager*)objectManager delegate:(id<RKObjectLoaderDelegate>)theDelegate
|
||||
{
|
||||
if ((self = [self initWithURL:[objectManager.baseURL URLByAppendingResourcePath:resourcePath] mappingProvider:objectManager.mappingProvider])) {
|
||||
[objectManager.client configureRequest:self];
|
||||
_delegate = theDelegate;
|
||||
|
||||
Reference in New Issue
Block a user