mirror of
https://github.com/zhigang1992/RestKit.git
synced 2026-04-27 22:41:10 +08:00
Miscellaneous cleanups
This commit is contained in:
@@ -25,6 +25,7 @@
|
||||
#import "RKManagedObjectSeeder.h"
|
||||
#import "RKManagedObjectCache.h"
|
||||
#import "RKManagedObjectMapping.h"
|
||||
#import "RKManagedObjectMappingOperation.h"
|
||||
#import "RKObjectPropertyInspector+CoreData.h"
|
||||
#import "RKSearchableManagedObject.h"
|
||||
#import "RKSearchWord.h"
|
||||
|
||||
@@ -111,7 +111,7 @@
|
||||
// set before the managed object store.
|
||||
if (self.targetObject && [self.targetObject isKindOfClass:[NSManagedObject class]]) {
|
||||
_deleteObjectOnFailure = [(NSManagedObject*)self.targetObject isNew];
|
||||
[self.objectStore save];
|
||||
[self.objectStore save:nil];
|
||||
_targetObjectID = [[(NSManagedObject*)self.targetObject objectID] retain];
|
||||
}
|
||||
|
||||
@@ -162,8 +162,9 @@
|
||||
// If the response was successful, save the store...
|
||||
if ([self.response isSuccessful]) {
|
||||
[self deleteCachedObjectsMissingFromResult:result];
|
||||
NSError* error = [self.objectStore save];
|
||||
if (error) {
|
||||
NSError *error = nil;
|
||||
BOOL success = [self.objectStore save:&error];
|
||||
if (! success) {
|
||||
RKLogError(@"Failed to save managed object context after mapping completed: %@", [error localizedDescription]);
|
||||
NSMethodSignature* signature = [(NSObject *)self.delegate methodSignatureForSelector:@selector(objectLoader:didFailWithError:)];
|
||||
RKManagedObjectThreadSafeInvocation* invocation = [RKManagedObjectThreadSafeInvocation invocationWithMethodSignature:signature];
|
||||
@@ -197,7 +198,7 @@
|
||||
NSManagedObject* objectToDelete = [self.objectStore objectWithID:_targetObjectID];
|
||||
if (objectToDelete) {
|
||||
[[self.objectStore managedObjectContext] deleteObject:objectToDelete];
|
||||
[self.objectStore save];
|
||||
[self.objectStore save:nil];
|
||||
} else {
|
||||
RKLogWarning(@"Unable to delete existing managed object with ID: %@. Object not found in the store.", _targetObjectID);
|
||||
}
|
||||
|
||||
@@ -163,8 +163,9 @@ NSString* const RKDefaultSeedDatabaseFileName = @"RKSeedDatabase.sqlite";
|
||||
}
|
||||
|
||||
- (void)finalizeSeedingAndExit {
|
||||
NSError* error = [[_manager objectStore] save];
|
||||
if (error != nil) {
|
||||
NSError *error = nil;
|
||||
BOOL success = [[_manager objectStore] save:&error];
|
||||
if (! success) {
|
||||
RKLogError(@"[RestKit] RKManagedObjectSeeder: Error saving object context: %@", [error localizedDescription]);
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
// RestKit
|
||||
//
|
||||
// Created by Blake Watters on 9/22/09.
|
||||
// Copyright 2009 Two Toasters
|
||||
// Copyright 2009 RestKit
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
@@ -111,7 +111,7 @@ extern NSString* const RKManagedObjectStoreDidFailSaveNotification;
|
||||
/**
|
||||
* Save the current contents of the managed object store
|
||||
*/
|
||||
- (NSError*)save;
|
||||
- (BOOL)save:(NSError **)error;
|
||||
|
||||
/**
|
||||
* This deletes and recreates the managed object context and
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
// RestKit
|
||||
//
|
||||
// Created by Blake Watters on 9/22/09.
|
||||
// Copyright 2009 Two Toasters
|
||||
// Copyright 2009 RestKit
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
@@ -184,21 +184,21 @@ static NSString* const RKManagedObjectStoreThreadDictionaryEntityCacheKey = @"RK
|
||||
Performs the save action for the application, which is to send the save:
|
||||
message to the application's managed object context.
|
||||
*/
|
||||
- (NSError*)save {
|
||||
- (BOOL)save:(NSError **)error {
|
||||
NSManagedObjectContext* moc = [self managedObjectContext];
|
||||
NSError *error = nil;
|
||||
|
||||
NSError *localError = nil;
|
||||
|
||||
@try {
|
||||
if (![moc save:&error]) {
|
||||
if (![moc save:&localError]) {
|
||||
if (self.delegate != nil && [self.delegate respondsToSelector:@selector(managedObjectStore:didFailToSaveContext:error:exception:)]) {
|
||||
[self.delegate managedObjectStore:self didFailToSaveContext:moc error:error exception:nil];
|
||||
[self.delegate managedObjectStore:self didFailToSaveContext:moc error:localError exception:nil];
|
||||
}
|
||||
|
||||
NSDictionary* userInfo = [NSDictionary dictionaryWithObject:error forKey:@"error"];
|
||||
NSDictionary* userInfo = [NSDictionary dictionaryWithObject:localError forKey:@"error"];
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:RKManagedObjectStoreDidFailSaveNotification object:self userInfo:userInfo];
|
||||
|
||||
if ([[error domain] isEqualToString:@"NSCocoaErrorDomain"]) {
|
||||
NSDictionary *userInfo = [error userInfo];
|
||||
if ([[localError domain] isEqualToString:@"NSCocoaErrorDomain"]) {
|
||||
NSDictionary *userInfo = [localError userInfo];
|
||||
NSArray *errors = [userInfo valueForKey:@"NSDetailedErrors"];
|
||||
if (errors) {
|
||||
for (NSError *detailedError in errors) {
|
||||
@@ -225,8 +225,13 @@ static NSString* const RKManagedObjectStoreThreadDictionaryEntityCacheKey = @"RK
|
||||
[userInfo valueForKey:@"NSValidationErrorPredicate"],
|
||||
[userInfo valueForKey:@"NSValidationErrorObject"]);
|
||||
}
|
||||
}
|
||||
return error;
|
||||
}
|
||||
|
||||
if (error) {
|
||||
*error = localError;
|
||||
}
|
||||
|
||||
return NO;
|
||||
}
|
||||
}
|
||||
@catch (NSException* e) {
|
||||
@@ -237,7 +242,8 @@ static NSString* const RKManagedObjectStoreThreadDictionaryEntityCacheKey = @"RK
|
||||
@throw;
|
||||
}
|
||||
}
|
||||
return nil;
|
||||
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (NSManagedObjectContext*)newManagedObjectContext {
|
||||
|
||||
@@ -74,8 +74,8 @@ typedef RKObjectMapping*(^RKDynamicObjectMappingDelegateBlock)(id);
|
||||
/**
|
||||
Return a new auto-released dynamic object mapping after yielding it to the block for configuration
|
||||
*/
|
||||
+ (RKDynamicObjectMapping *)dynamicMappingUsingBlock:(void(^)(RKDynamicObjectMapping *))block;
|
||||
+ (RKDynamicObjectMapping *)dynamicMappingWithBlock:(void(^)(RKDynamicObjectMapping *))block DEPRECATED_ATTRIBUTE;
|
||||
+ (RKDynamicObjectMapping *)dynamicMappingUsingBlock:(void(^)(RKDynamicObjectMapping *dynamicMapping))block;
|
||||
+ (RKDynamicObjectMapping *)dynamicMappingWithBlock:(void(^)(RKDynamicObjectMapping *dynamicMapping))block DEPRECATED_ATTRIBUTE;
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -167,7 +167,7 @@ relationship. Relationships are processed using an object mapping as well.
|
||||
}];
|
||||
}];
|
||||
*/
|
||||
+ (id)mappingForClass:(Class)objectClass usingBlock:(void (^)(RKObjectMapping *))block;
|
||||
+ (id)mappingForClass:(Class)objectClass usingBlock:(void (^)(RKObjectMapping *mapping))block;
|
||||
|
||||
/**
|
||||
Returns serialization mapping for encoding a local object to a dictionary for transport. The RKObjectMapping instance will
|
||||
@@ -190,7 +190,7 @@ relationship. Relationships are processed using an object mapping as well.
|
||||
|
||||
Using the block forms we are able to quickly configure and send this request on the fly.
|
||||
*/
|
||||
+ (id)serializationMappingUsingBlock:(void (^)(RKObjectMapping*))block;
|
||||
+ (id)serializationMappingUsingBlock:(void (^)(RKObjectMapping *serializationMapping))block;
|
||||
#endif
|
||||
|
||||
/**
|
||||
|
||||
@@ -29,7 +29,7 @@
|
||||
return [[self new] autorelease];
|
||||
}
|
||||
|
||||
+ (RKObjectMappingProvider *)mappingProviderUsingBlock:(void (^)(RKObjectMappingProvider *))block {
|
||||
+ (RKObjectMappingProvider *)mappingProviderUsingBlock:(void (^)(RKObjectMappingProvider *mappingProvider))block {
|
||||
RKObjectMappingProvider* mappingProvider = [self mappingProvider];
|
||||
block(mappingProvider);
|
||||
return mappingProvider;
|
||||
|
||||
@@ -648,7 +648,7 @@ static NSString* lastUpdatedDateDictionaryKey = @"lastUpdatedDateDictionaryKey";
|
||||
[self loadTableWithObjectLoader:[self.objectManager loaderWithResourcePath:resourcePath]];
|
||||
}
|
||||
|
||||
- (void)loadTableFromResourcePath:(NSString *)resourcePath usingBlock:(void (^)(RKObjectLoader*))block {
|
||||
- (void)loadTableFromResourcePath:(NSString *)resourcePath usingBlock:(void (^)(RKObjectLoader *loader))block {
|
||||
RKObjectLoader* theObjectLoader = [self.objectManager loaderWithResourcePath:resourcePath];
|
||||
block(theObjectLoader);
|
||||
[self loadTableWithObjectLoader:theObjectLoader];
|
||||
|
||||
@@ -134,7 +134,7 @@
|
||||
[self addRowForAttribute:attributeKeyPath withControlType:controlType usingBlock:nil];
|
||||
}
|
||||
|
||||
- (void)addRowMappingAttribute:(NSString *)attributeKeyPath toKeyPath:(NSString *)cellKeyPath onCellWithClass:(Class)cellClass usingBlock:(void (^)(RKTableItem *))block {
|
||||
- (void)addRowMappingAttribute:(NSString *)attributeKeyPath toKeyPath:(NSString *)cellKeyPath onCellWithClass:(Class)cellClass usingBlock:(void (^)(RKTableItem *tableItem))block {
|
||||
RKTableItem *tableItem = [RKTableItem tableItem];
|
||||
tableItem.cellMapping.cellClass = cellClass;
|
||||
RKObjectAttributeMapping *attributeMapping = [[RKObjectAttributeMapping new] autorelease];
|
||||
|
||||
@@ -71,7 +71,7 @@
|
||||
RKHuman* human = [RKHuman object];
|
||||
human.name = @"Blake Watters";
|
||||
human.railsID = [NSNumber numberWithInt:1];
|
||||
[objectManager.objectStore save];
|
||||
[objectManager.objectStore save:nil];
|
||||
|
||||
assertThat(objectManager.objectStore.managedObjectContext, is(equalTo(store.managedObjectContext)));
|
||||
|
||||
@@ -128,7 +128,7 @@
|
||||
other.railsID = [NSNumber numberWithInt:456];
|
||||
RKHuman* deleteMe = [RKHuman createEntity];
|
||||
deleteMe.railsID = [NSNumber numberWithInt:9999];
|
||||
[store save];
|
||||
[store save:nil];
|
||||
assertThatUnsignedInteger([RKHuman count:nil], is(equalToInt(3)));
|
||||
|
||||
RKObjectManager* objectManager = RKTestNewObjectManager();
|
||||
@@ -169,7 +169,7 @@
|
||||
deleteOdd.railsID = [NSNumber numberWithInt:9999];
|
||||
RKHuman* doNotDeleteMe = [RKHuman createEntity];
|
||||
doNotDeleteMe.railsID = [NSNumber numberWithInt:1000];
|
||||
[store save];
|
||||
[store save:nil];
|
||||
assertThatUnsignedInteger([RKHuman count:nil], is(equalToInt(4)));
|
||||
|
||||
RKObjectManager* objectManager = RKTestNewObjectManager();
|
||||
@@ -217,7 +217,7 @@
|
||||
deleteOdd.railsID = [NSNumber numberWithInt:9999];
|
||||
RKHuman* doNotDeleteMe = [RKHuman createEntity];
|
||||
doNotDeleteMe.railsID = [NSNumber numberWithInt:1000];
|
||||
[store save];
|
||||
[store save:nil];
|
||||
assertThatUnsignedInteger([RKHuman count:nil], is(equalToInt(4)));
|
||||
|
||||
RKObjectManager* objectManager = RKTestNewObjectManager();
|
||||
@@ -274,7 +274,7 @@
|
||||
blake.railsID = [NSNumber numberWithInt:123];
|
||||
RKHuman* other = [RKHuman createEntity];
|
||||
other.railsID = [NSNumber numberWithInt:456];
|
||||
[objectStore save];
|
||||
[objectStore save:nil];
|
||||
assertThatInteger([RKHuman count:nil], is(equalToInteger(2)));
|
||||
|
||||
[objectManager.mappingProvider setMapping:humanMapping forKeyPath:@"human"];
|
||||
|
||||
@@ -68,7 +68,7 @@
|
||||
RKCat* cat = [RKCat object];
|
||||
cat.name = @"Asia";
|
||||
cat.railsID = [NSNumber numberWithInt:31337];
|
||||
[objectStore save];
|
||||
[objectStore save:nil];
|
||||
|
||||
NSDictionary* mappableData = [NSDictionary dictionaryWithKeysAndObjects:@"name", @"Blake", @"favoriteCatID", [NSNumber numberWithInt:31337], nil];
|
||||
RKHuman* human = [RKHuman object];
|
||||
@@ -97,7 +97,7 @@
|
||||
RKCat* cat = [RKCat object];
|
||||
cat.name = @"Asia";
|
||||
cat.railsID = [NSNumber numberWithInt:31337];
|
||||
[objectStore save];
|
||||
[objectStore save:nil];
|
||||
|
||||
NSDictionary* mappableData = [NSDictionary dictionaryWithKeysAndObjects:@"name", @"Blake", @"favoriteCatID", [NSNumber numberWithInt:31337], nil];
|
||||
RKHuman* human = [RKHuman object];
|
||||
@@ -131,7 +131,7 @@
|
||||
roy.name = @"Reginald Royford Williams III";
|
||||
roy.railsID = [NSNumber numberWithInt:31338];
|
||||
|
||||
[objectStore save];
|
||||
[objectStore save:nil];
|
||||
|
||||
NSArray *catIDs = [NSArray arrayWithObjects:[NSNumber numberWithInt:31337], [NSNumber numberWithInt:31338], nil];
|
||||
NSDictionary* mappableData = [NSDictionary dictionaryWithKeysAndObjects:@"name", @"Blake", @"catIDs", catIDs, nil];
|
||||
@@ -219,7 +219,7 @@
|
||||
RKCat* cat = [RKCat object];
|
||||
cat.name = @"Asia";
|
||||
cat.railsID = [NSNumber numberWithInt:31337];
|
||||
[objectStore save];
|
||||
[objectStore save:nil];
|
||||
|
||||
NSDictionary* mappableData = [NSDictionary dictionaryWithKeysAndObjects:@"name", @"Blake", @"favoriteCatID", [NSNumber numberWithInt:31337], nil];
|
||||
RKHuman* human = [RKHuman object];
|
||||
@@ -248,7 +248,7 @@
|
||||
RKCat* cat = [RKCat object];
|
||||
cat.name = @"Asia";
|
||||
cat.railsID = [NSNumber numberWithInt:31337];
|
||||
[objectStore save];
|
||||
[objectStore save:nil];
|
||||
|
||||
NSDictionary* mappableData = [NSDictionary dictionaryWithKeysAndObjects:@"name", @"Blake", @"favoriteCatID", [NSNumber numberWithInt:31337], nil];
|
||||
RKHuman* human = [RKHuman object];
|
||||
|
||||
@@ -75,7 +75,7 @@
|
||||
|
||||
RKHuman* human = [RKHuman object];
|
||||
human.railsID = [NSNumber numberWithInt:123];
|
||||
[store save];
|
||||
[store save:nil];
|
||||
assertThatBool([RKHuman hasAtLeastOneEntity], is(equalToBool(YES)));
|
||||
|
||||
NSDictionary* data = [NSDictionary dictionaryWithObject:[NSNumber numberWithInt:123] forKey:@"id"];
|
||||
@@ -94,7 +94,7 @@
|
||||
[RKHuman truncateAll];
|
||||
RKHuman* human = [RKHuman object];
|
||||
human.railsID = [NSNumber numberWithInt:123];
|
||||
[store save];
|
||||
[store save:nil];
|
||||
assertThatBool([RKHuman hasAtLeastOneEntity], is(equalToBool(YES)));
|
||||
|
||||
NSDictionary* data = [NSDictionary dictionaryWithObject:[NSNumber numberWithInt:123] forKey:@"id"];
|
||||
|
||||
@@ -33,7 +33,7 @@
|
||||
objectManager.objectStore = objectStore;
|
||||
RKHuman* human = [RKHuman createEntity];
|
||||
human.railsID = [NSNumber numberWithInt:1234];
|
||||
[objectStore save];
|
||||
[objectStore save:nil];
|
||||
NSManagedObject* newReference = [objectStore findOrCreateInstanceOfEntity:[RKHuman entity] withPrimaryKeyAttribute:@"railsID" andValue:@"1234"];
|
||||
assertThat(newReference, is(equalTo(human)));
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
RKSearchable* searchable = [RKSearchable createEntity];
|
||||
searchable.title = @"This is the title of my new object";
|
||||
assertThat(searchable.searchWords, is(empty()));
|
||||
[store save];
|
||||
[store save:nil];
|
||||
assertThat(searchable.searchWords, isNot(empty()));
|
||||
assertThat(searchable.searchWords, hasCountOf(8));
|
||||
}
|
||||
|
||||
@@ -93,7 +93,7 @@
|
||||
// spec pass. Without it we are crashing inside the mapper internals. Believe
|
||||
// that we just need a way to save the context before we begin mapping or something
|
||||
// on success. Always saving means that we can abandon objects on failure...
|
||||
[_objectManager.objectStore save];
|
||||
[_objectManager.objectStore save:nil];
|
||||
RKTestResponseLoader* loader = [RKTestResponseLoader responseLoader];
|
||||
[_objectManager postObject:temporaryHuman delegate:loader];
|
||||
[loader waitForResponse];
|
||||
@@ -130,7 +130,7 @@
|
||||
[mapping mapAttributes:@"name", nil];
|
||||
|
||||
// Save it to suppress deletion
|
||||
[_objectManager.objectStore save];
|
||||
[_objectManager.objectStore save:nil];
|
||||
|
||||
RKTestResponseLoader* loader = [RKTestResponseLoader responseLoader];
|
||||
NSString* resourcePath = @"/humans/fail";
|
||||
|
||||
Reference in New Issue
Block a user