デバッグが非常に難しい非常に奇妙なバグがあります。フェッチされた 1 つのオブジェクトに対して設定されていない 1 対多の関係があります。Restkit と Core Data を使用しています。ダウンロードしたjsonは次のとおりです。
{ "chapterExerciseFiles" : [ ],
"chapterExerciseUrls" : [ { "description" : "",
"id" : 43,
"name" : "Webbˆvning",
"title" : "Webbˆvningar",
"type" : "WEB_EXERCISE_LINK",
"url" : "http://..."
} ],
"fromPage" : 1,
"id" : 43,
"index" : 1,
"isbn" : "9789127434400",
"pageExercises" : [ ],
"title" : "Echo 5 Short Stories",
"toPage" : 5
} //...
モデルは次のようになります。
マッピング:
+ (RKEntityMapping *)chapterExerciseMapping
{
RKEntityMapping *chapterExerciseMapping = [RKEntityMapping mappingForEntityForName:@"ChapterExercise" inManagedObjectStore:[RKObjectManager sharedManager].managedObjectStore];
[chapterExerciseMapping addAttributeMappingsFromArray:@[
@"index",
@"title"
]];
[chapterExerciseMapping addAttributeMappingsFromDictionary:@{
@"id": @"chapterExerciseID",
@"toPage": @"toPageNumber",
@"fromPage": @"fromPageNumber"
}];
[chapterExerciseMapping addRelationshipMappingWithSourceKeyPath:@"chapterExerciseFiles" mapping:[IBResponseMapping exerciseFileMapping]];
[chapterExerciseMapping addRelationshipMappingWithSourceKeyPath:@"chapterExerciseUrls" mapping:[IBResponseMapping exerciseUrlMapping]];
[chapterExerciseMapping addRelationshipMappingWithSourceKeyPath:@"pageExercises" mapping:[IBResponseMapping pageExerciseMapping]];
return chapterExerciseMapping;
}
+ (RKEntityMapping *)exerciseUrlMapping
{
RKEntityMapping *exerciseUrlMapping = [RKEntityMapping mappingForEntityForName:@"ExerciseUrl" inManagedObjectStore:[RKObjectManager sharedManager].managedObjectStore];
[exerciseUrlMapping addAttributeMappingsFromArray:@[
@"type",
@"url"
]];
[exerciseUrlMapping addAttributeMappingsFromDictionary:@{
@"description": @"urlDescription",
@"id" : @"urlID",
@"name" : @"title",
@"title" : @"sectionTitle"
}];
return exerciseUrlMapping;
}
奇妙なことに、「一部」chapterExercisesUrls
は設定されますが、最初は設定されません。
Restkit をログに記録するchapterExerciseUrls
と、フェッチ時に空であることが示されます。
<IBChapterExercise: 0x16f2f6b0> (entity: ChapterExercise; id: 0x16f2f6f0 <x-coredata:///ChapterExercise/t529D851C-D8EF-4669-B197-9FF24B5CAE862267> ; data: {
bookData = nil;
chapterExerciseFiles = (
);
chapterExerciseID = 43;
chapterExerciseUrls = (
);
fromPageNumber = 1;
index = 1;
pageExercises = (
);
title = "Echo 5 Short Stories";
toPageNumber = 5;
}),
適切なマッピングを取得する別のオブジェクトを次に示します。
<IBChapterExercise: 0x14c73920> (entity: ChapterExercise; id: 0x14c8bae0 <x-coredata:///ChapterExercise/t529D851C-D8EF-4669-B197-9FF24B5CAE862295> ; data: {
bookData = nil;
chapterExerciseFiles = (
);
chapterExerciseID = 45;
chapterExerciseUrls = (
"0x14ca2f60 <x-coredata:///ExerciseUrl/t529D851C-D8EF-4669-B197-9FF24B5CAE862296>"
);
fromPageNumber = 16;
index = 3;
pageExercises = (
"0x14cbea40 <x-coredata:///PageExercise/t529D851C-D8EF-4669-B197-9FF24B5CAE862300>",
"0x14c98af0 <x-coredata:///PageExercise/t529D851C-D8EF-4669-B197-9FF24B5CAE862297>",
"0x16f30000 <x-coredata:///PageExercise/t529D851C-D8EF-4669-B197-9FF24B5CAE862305>"
);
title = "Right up to the Limits";
toPageNumber = 25;
}),
この問題は、OSX と iOS の両方で見られます。これをさらにデバッグする方法についてのアイデアはありますか?