2
我用RestKit映射兩類對象。當我自己做他們中的任何一個時,它都能很好地工作。但是,當我把它們放在一起,它會在RKObjectMappingOperation.m
崩潰在線449
,Restkit對象映射兩類不良訪問
[destinationSet setSet:destinationObject];
隨着"EXC_BAD_ACCESS"
錯誤。
這裏是我的兩個映射方法:
- (RKObjectLoader *)saves
{
// Create an object manager and connect core data's persistent store to it
RKObjectManager *objectManager = [RKObjectManager sharedManager];
RKManagedObjectStore* objectStore = [RKManagedObjectStore objectStoreWithStoreFilename:@"Db.sqlite"];
objectManager.objectStore = objectStore;
// Define our author mapping for saved places
RKManagedObjectMapping *authorMapping = [RKManagedObjectMapping mappingForEntityWithName:@"Person"];
[authorMapping mapAttributes:@"uid", nil];
// Define our place mapping
RKManagedObjectMapping *placeMapping = [RKManagedObjectMapping mappingForEntityWithName:@"Place"];
[placeMapping mapAttributes:@"uid",@"name",@"address", nil];
// Now, connect the two via a save
RKManagedObjectMapping *saveMapping = [RKManagedObjectMapping mappingForEntityWithName:@"Save"];
[saveMapping mapAttributes:@"uid", @"timestamp", nil];
[saveMapping mapKeyPath:@"place" toRelationship:@"place" withMapping:placeMapping];
[saveMapping mapKeyPath:@"author" toRelationship:@"author" withMapping:authorMapping];
// We expect to find the place entity inside of a dictionary keyed "saves"
[objectManager.mappingProvider setMapping:saveMapping forKeyPath:@"saves"];
// Prepare our object loader to load and map objects from remote server, and send
RKObjectLoader *objectLoader = [objectManager objectLoaderWithResourcePath:@"places/saves" delegate:self];
objectLoader.method = RKRequestMethodGET;
[objectLoader send];
return objectLoader;
}
- (RKObjectLoader *)recommends
{
// Create an object manager and connect core data's persistent store to it
RKObjectManager *objectManager = [RKObjectManager sharedManager];
RKManagedObjectStore* objectStore = [RKManagedObjectStore objectStoreWithStoreFilename:@"Db.sqlite"];
objectManager.objectStore = objectStore;
// Define our author mapping for recommended places
RKManagedObjectMapping *authorMapping = [RKManagedObjectMapping mappingForEntityWithName:@"Person"];
[authorMapping mapAttributes:@"uid", nil];
// Define our place mapping
RKManagedObjectMapping *placeMapping = [RKManagedObjectMapping mappingForEntityWithName:@"Place"];
[placeMapping mapAttributes:@"uid",@"name",@"address", nil];
// Now, connect the two via a recommend
RKManagedObjectMapping *recommendMapping = [RKManagedObjectMapping mappingForEntityWithName:@"Recommend"];
[recommendMapping mapAttributes:@"uid", @"timestamp", nil];
[recommendMapping mapKeyPath:@"place" toRelationship:@"place" withMapping:placeMapping];
[recommendMapping mapKeyPath:@"author" toRelationship:@"author" withMapping:authorMapping];
// We expect to find the place entity inside of a dictionary keyed "recommends"
[objectManager.mappingProvider setMapping:recommendMapping forKeyPath:@"recommends"];
// Prepare our object loader to load and map objects from remote server, and send
RKObjectLoader *objectLoader = [objectManager objectLoaderWithResourcePath:@"places/recommends" delegate:self];
objectLoader.method = RKRequestMethodGET;
[objectLoader send];
return objectLoader;
}
當我打電話一個,或其他的,它的工作原理。當我打電話時,
[self saves];
[self recommends];
它崩潰。任何想法爲什麼?
你很棒。非常感謝你。 +50給你! – john 2012-02-22 22:51:02