我正在尝试使用rest kit将新的托管对象发布到服务器,但我不知道我做错了什么.我得到如下例外情况:
由于未捕获的异常'NSInvalidArgumentException'而终止应用程序,原因:'
RKRequestDescriptor对象必须使用目标类为的映射进行初始化NSMutableDictionary,得到'用户'(请参阅参考资料[RKObjectMapping requestMapping])'
我正在寻找像这样的堆栈溢出帖子的解决方案 这是我从MappingProvider类的实体映射方法:
+(RKMapping *)usersMapping
{
RKEntityMapping *mapping = [RKEntityMapping mappingForEntityForName:@"Users" inManagedObjectStore:[[DateModel sharedDataModel]objectStore]];
[mapping addAttributeMappingsFromDictionary:@{
@"id": @"user_id",
@"address1": @"address1",
@"address2": @"address2",
@"created_at":@"created_at",
@"updated_at": @"updated_at",
@"email": @"email",
@"name":@"name",
@"password_digest": @"password_digest",
@"phone_no": @"phone_no",
@"postcode":@"postcode",
@"remember_token":@"remember_token",
@"user_type": @"user_type",
@"apns_token":@"apns_token"
}
];
[mapping addRelationshipMappingWithSourceKeyPath:@"admins" mapping:[MappingProvider adminsMapping]];
[mapping addRelationshipMappingWithSourceKeyPath:@"carers" mapping:[MappingProvider carersMapping]];
[mapping addRelationshipMappingWithSourceKeyPath:@"customers" mapping:[MappingProvider customersMapping]];
[mapping addRelationshipMappingWithSourceKeyPath:@"userWearers" mapping:[MappingProvider customersMapping]];
return mapping;
Run Code Online (Sandbox Code Playgroud)
这是用户填写所有文本字段并单击注册按钮时调用的方法:
-(void)registerUser
{RKResponseDescriptor *userResponseDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:[MappingProvider usersMapping] method:RKRequestMethodPOST pathPattern:nil keyPath:nil statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful)];
//here …Run Code Online (Sandbox Code Playgroud)