我有一個奇怪的問題,將對象數組映射到核心數據項。iOS RestKit實體管理器映射對象陣列
用戶實體映射和的ObjectManager代碼:
RKEntityMapping *objectMapping = [RKEntityMapping mappingForEntityForName:@"User" inManagedObjectStore:[RKObjectManager sharedManager].managedObjectStore];
[objectMapping addAttributeMappingsFromDictionary:@{@"id": @"user_id",
@"first_name": @"first_name",
@"middle_name":@"middle_name",
@"last_name":@"last_name",
@"phone":@"phone",
@"job_title":@"job_title",
@"roles":@"roles",
@"email":@"email",
@"created_at":@"created_at",
@"updated_at":@"updated_at",
@"avatar_urls":@"avatar_urls",
@"skills":@"skills",
@"interests":@"interests",
@"birth_date":@"birth_date"}];
RKEntityMapping *userMapping = [User entityMapping];
[manager addResponseDescriptor:[RKResponseDescriptor responseDescriptorWithMapping:userMapping
method:RKRequestMethodGET
pathPattern:@"users/:id"
keyPath:nil
statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful)]];
[manager addResponseDescriptor:[RKResponseDescriptor responseDescriptorWithMapping:userMapping
method:RKRequestMethodGET
pathPattern:@"users"
keyPath:nil
statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful)]];
下面是用戶實體的陣列的簡單例子。
{
User1,
User2,
User3
}
查看來自RestKit的調試日誌,所有內容都映射到正確的值。但是當我查看最終結果時,映射數組的項目數量正確,但它們都是User3。同樣,數據庫也有User3。用戶1和用戶2從不存儲在數據庫中。
我一直在想弄清楚我出錯的地方。任何幫助表示讚賞。
UPDATE:
[manager getObjectsAtPath:@"users"
parameters:@{@"token":token}
success:success failure:failure];
[
{
"avatar_urls": {
"large": "",
"medium": "",
"small": "",
"thumb": "",
"icon": ""
},
"id": 631,
"roles": [
"company_admin"
],
"created_at": "2013-10-23T15:59:06.256-05:00",
"updated_at": "2013-10-27T16:51:31.947-05:00",
"skills": [],
"interests": [],
"birth_date": null,
"phone_message_channel": true,
"email_message_channel": true,
"first_name": "User",
"last_name": "One",
"email": "",
"phone": null,
"job_title": null
},
{
"avatar_urls": {
"large": "",
"medium": "",
"small": "",
"thumb": "",
"icon": ""
},
"id": 633,
"roles": [
"company_admin"
],
"created_at": "2013-10-23T16:07:46.472-05:00",
"updated_at": "2013-10-27T16:51:26.148-05:00",
"skills": [],
"interests": [],
"birth_date": null,
"phone_message_channel": true,
"email_message_channel": true,
"first_name": "User",
"last_name": "two",
"email": "",
"phone": "",
"job_title": ""
},
{
"avatar_urls": {
"large": "",
"medium": "",
"small": "",
"thumb": "",
"icon": ""
},
"id": 632,
"roles": [
"company_admin"
],
"created_at": "2013-10-23T16:07:12.295-05:00",
"updated_at": "2013-11-01T20:11:26.607-05:00",
"skills": [],
"interests": [],
"birth_date": "",
"phone_message_channel": true,
"email_message_channel": true,
"first_name": "User",
"last_name": "Three",
"email": "",
"phone": "",
"job_title": ""
}
]
爲了重申在成功塊映射的結果示出了在陣列3項和所有都是用戶3。我也查詢核心數據,並確認它僅添加/爲用戶模型更新了一行。
FIX 不必分發帖回答自己..所以加入作爲更新
我忘了補充identificationAttributes我的用戶模型。一旦我將它設置爲我的ID,一切都像魅力..... =。=睡眠剝奪是不好的......
顯示一些真正的JSON以及您如何提出請求。 – Wain