下面是我用于类的代码:
@interface DBUser : NSManagedObject
@property (nonatomic, retain) NSString * username;
@property (nonatomic, retain) NSString * email;
@property (nonatomic, retain) NSString * accessToken;
@property (nonatomic, retain) NSNumber * userID;
@end
@implementation DBUser
@dynamic username;
@dynamic email;
@dynamic userID;
@dynamic accessToken;
@end
这是我的映射:
RKManagedObjectMapping* userMapping = [RKObjectMapping mappingForClass:[DBUser class]];
userMapping.setDefaultValueForMissingAttributes = NO;
[userMapping mapKeyPathsToAttributes:
@"id", @"userID",
@"email", @"email",
@"username", @"username",
@"access_token", @"accessToken",
nil];
[objectManager.mappingProvider registerMapping:userMapping withRootKeyPath:@"user"];
和路线:
[objectManager.mappingProvider registerMapping:userMapping withRootKeyPath:@"user"];
这是从服务返回的 json 对象:
{
"user": {
"id": 1,
"username": "username",
"email": "email@email.com",
"access_token": "59f99efcffa9af7252d5ce1839082bd7e740e289e2577dda592c68647dc4e0db"
}
}
但是在objectDidLoad
方法中我遇到了一些数据失败:
<DBUser: 0x5939cc0> (entity: DBUser; id: 0x4f432e0 <x-coredata://6F302428-0538-41D0-9627-81C80E905DA8/DBUser/p11> ; data: <fault>)
在这里,我附上了跟踪的完整日志。它可以很好地检测对象映射,但是当我得到self
它时不显示任何数据。
这段代码有什么问题或我在其中缺少什么?