지난 몇 일간 RestKit 0.23.1을 사용하여이 JSON 데이터를 Core Data의 관리 대상 객체에 매핑하는 방법을 고민했습니다. 내 맵핑을 구축 할 수 있도록하는 기능을 만들었습니다RestKit 0.23.1 일대 다 관계 매핑이 작동하지 않습니다.
objects": [
{
"id": "03fbbec709d261c87a64d979fe1e530b",
"object_type": "note",
"links": [
{
"id": "d48066cf6daa007e31f8915831f46fc2",
"urlSite": "techcrunch.com",
"siteName": null,
"urlString": "http://techcrunch.com/2014/06/16/secret-finally-lets-all-your-freaky-friends-have-their-own-feed/",
"urlShortened": "http://gcq.me/1vzsVJY",
"title": "Secret Finally Lets All Your Freaky Friends Have Their Own Feeds | TechCrunch",
"previewImage": "http://tctechcrunch2011.files.wordpress.com/2014/06/secret2.jpg?w=650",
"previewText": "Secret Finally Lets All Your Freaky Friends Have Their Own Feeds | TechCrunch",
"lastUpdated": "2014-06-17 06:50:56",
"lastVisited": "2014-06-17 06:50:56",
"visitCount": 0
}
]
}]
: 내 데이터는 URL에 미리 정보를 포함하는 구조화 된 개체를 하나 이상 "링크"자체 목록을 가지고 각각의 여러 "객체"를 포함 관계 :
+ (RKEntityMapping*)webLinkMapping {
RKManagedObjectStore* managedObjectStore = [RKManagedObjectStore defaultStore];
RKEntityMapping *mapping = [RKEntityMapping mappingForEntityForName:@"WebLink" inManagedObjectStore:managedObjectStore];
mapping.identificationAttributes = @[ @"objectId" ];
[mapping addAttributeMappingsFromDictionary:@{@"id": @"objectId"}];
[mapping addAttributeMappingsFromArray:@[ @"urlSite", @"siteName", @"urlString", @"urlShortened",
@"title", @"previewImage", @"previewText", @"lastUpdated",
@"lastVisited", @"visitCount"]];
return mapping;
}
+ (RKEntityMapping*)streamObjectMapping {
RKManagedObjectStore* managedObjectStore = [RKManagedObjectStore defaultStore];
RKEntityMapping *mapping = [RKEntityMapping mappingForEntityForName:@"StreamObject" inManagedObjectStore:managedObjectStore];
mapping.identificationAttributes = @[ @"objectId" ];
[mapping addAttributeMappingsFromDictionary:@{
@"id": @"objectId",
}];
[mapping addAttributeMappingsFromArray:@[ @"object_type"]];
[mapping addRelationshipMappingWithSourceKeyPath:@"links" mapping:[self webLinkMapping]];
//[mapping addPropertyMapping:[RKRelationshipMapping relationshipMappingFromKeyPath:@"links" toKeyPath:@"links" withMapping:[self webLinkMapping]]];
return mapping;
}
내가 잘 작동하지 내 매핑의 원인이되는 JSON에서 반환되는 링크의 배열 대괄호 한 쌍의 거의 확실 해요.
links = "<relationship fault: 0x114a05820 'links'>";
, 내가 개체가 부모 개체에서 올바른 관련된 OBJECTID에 저장되는 내 링크를보고 있어요 SQLite는 브라우저를 사용하여 실제 데이터 테이블에서 찾고, 그래서 : 내 반환 스트림 객체에 관계 오류가 계속 그들은 스트림 객체를 요청할 때 올바르게 반환되지 않습니다. 이 문제를 어떻게 수정했는지 생각해보십시오. 메모리에 로딩에 관한
, 그것은 그렇게하지 않는 것 "장소"와 "사용자가"확인 표시 방법
RKStreamObject* postObject = [_postObjects objectAtIndex:indexPath.row];
NSLog(@"Links: %@", postObject.links);
2014-06-20 11:25:11.249 MyApp[6026:151920] Links: Relationship 'links' fault on managed object (0x110c47ee0) <RKStreamObject: 0x110c47ee0> (entity: StreamObject; id: 0xd000000001000000 <x-coredata://F96BC470-82A5-4C56-81A9-71C6129F967B/StreamObject/p64> ; data: {
body = "http://techcrunch.com/2014/06/16/secret-finally-lets-all-your-freaky-friends-have-their-own-feed/";
"comment_count" = 0;
controllerSource = nil;
"gc_updated" = "2014-06-20 16:25:10 +0000";
"liked_by_me" = 0;
likes = 0;
links = "<relationship fault: 0x1141bce40 'links'>";
objectId = 03fbbec709d261c87a64d979fe1e530b;
"object_type" = note;
photo = nil;
"photo_feed" = nil;
"photo_height" = 0;
"photo_width" = 0;
place = "0xd000000000100002 <x-coredata://F96BC470-82A5-4C56-81A9-71C6129F967B/Place/p4>";
privacy = F;
"subscribed_by_me" = 1;
timestamp = "2014-06-17T06:51:00-05:00";
"timestamp_as_words" = "3 days ago";
"timestamp_formatted" = "Tuesday, June 17, 2014 at 06:51:00 CDT";
"timestamp_unix" = 1403005860;
user = "0xd0000000000c0004 <x-coredata://F96BC470-82A5-4C56-81A9-71C6129F967B/User/p3>";
videoId = nil;
videoSource = nil;
})
공지를? 이것들은 잘 작동하는 일대일 객체 매핑입니다. NSLog 문에서와 같이 직접 호출 할 때 링크가 나타나지 않아야합니까?
마지막 편집은 Wain의 제안에 따라 관계 배열에서 첫 번째 객체를 가져 와서 관련 웹 링크를 반환합니다.
if ([postObject.links count] > 0) {
RKWebLink *link = [[postObject.links allObjects] objectAtIndex:0];
NSLog(@"Link title: %@", link.title);
}
다른 비슷한 스레드와 동일한 응답을 기반으로, 링크 변수에 액세스 할 때 동일한 오류가 발생한다는 것을 제외하고 나는 당신과 동의하는 경향이 있습니다. 나는 링크에 액세스하려고 시도하는 방법을 보여주기 위해 게시물에 더 많은 정보를 추가했습니다. – webguyatwork
관계에서 첫 번째 항목을 추출하고 기록하십시오. 오류는 가능한 한 많이 발사되므로 데이터가 실행되고로드되지 않습니다. – Wain
당신, 선생님, 생명의 은인입니다! 나는 (어쩌면, 어쩌면 결국) 그렇게하려고 생각하지 않았을 것이다. 이것은 내가 필요한 것입니다. 고맙습니다!! – webguyatwork