I just installed framework restkit 0.9.3 and followed the example of the Discussion Board. Well, everything just works fine, however, when I tried to use Core Data, my custom NSManagedObject class duplicates even after declaring it primaryKeyAttribute (userID). For example, when I send a login request to my web server, I return {"user":{"id":1, "username":"teste", ...}} .. but it seems to be creating a new a line every time it calls objectLoader: didLoadObjects.
User table:

Code example:
~ AppDelegate.m didFinishLaunching
RKManagedObjectMapping* userMapping = [RKManagedObjectMapping mappingForClass:[User class]]; userMapping.primaryKeyAttribute = @"userID"; userMapping.setDefaultValueForMissingAttributes = YES; // clear out any missing attributes (token on logout) [userMapping mapKeyPathsToAttributes: @"id", @"userID", @"email", @"email", @"username", @"username", @"password", @"password", nil]; [objectManager.mappingProvider registerMapping:userMapping withRootKeyPath:@"user"];
~ User .m loginWithDelegate
- (void)loginWithDelegate:(NSObject<UserAuthenticationDelegate>*)delegate { _delegate = delegate; [[RKObjectManager sharedManager] postObject:self delegate:self block:^(RKObjectLoader* loader) { loader.resourcePath = @"/login"; loader.serializationMapping = [RKObjectMapping serializationMappingWithBlock:^(RKObjectMapping* mapping) { [mapping mapAttributes:@"username", @"password", nil]; }]; }]; }
~ User .m didLoadObjects (RKObjectLoaderDelegate)
- (void)objectLoader:(RKObjectLoader*)objectLoader didLoadObjects:(NSArray *)objects { if ([objectLoader wasSentToResourcePath:@"/login"]) { [self loginWasSuccessful]; } NSLog(@"number of user rows: %i", [User findAll].count); }
What am I doing wrong?
mateusmaso
source share