4

アプリにrestkit0.10.2を使用しています。サーバーからデータをフェッチしてDBに保存するさまざまなテーブルがあります。

3つのテーブルがあります。1つのマスターテーブルと2つの子テーブルです。両方の子テーブルは、マスターテーブルと1対1の関係にあります。

ここに画像の説明を入力してください

2つの異なるViewControllerV1とV2があり、Webサービスを呼び出してデータをテーブルChild1とChild2にマッピングしています。Child1、Child2、およびMasterテーブルには、主キーとしてuserIDがあります。

ViewController V1 / V2をクリックすると、以下のプロセスが実行されます。

1) Getting Data from Server.
2) Delete UserID from Child1/Child2 table(if any), not deleting details in Master Table. Delete Rule is nullify.
3) Map userID to Child1/Child2 Table and Other Details(name, age, userId etc) with Master Table.

マッピングコード:

RKManagedObjectMapping *userDetailMapping = [RKManagedObjectMapping mappingForClass:[Master class] inManagedObjectStore:manager.objectStore];
        [userDetailMapping mapKeyPath:@"uid" toAttribute:@"userID"];
        [userDetailMapping mapKeyPath:@"ne" toAttribute:@"name"];
        [userDetailMapping mapKeyPath:@"email" toAttribute:@"email"];
[manager.mappingProvider setMapping:userDetailMapping forKeyPath:@"users"];

        userDetailMapping.primaryKeyAttribute = @"userID";


RKManagedObjectMapping *userkeyMapping1 = [RKManagedObjectMapping mappingForClass:[Child1 class] inManagedObjectStore:manager.objectStore];
        [userkeyMapping1 mapKeyPath:@"uk" toAttribute:@"userID"];
        userkeyMapping1.primaryKeyAttribute = @"userID";
        [manager.mappingProvider setMapping:userkeyMapping1 forKeyPath:@"usk1"];

 RKManagedObjectMapping *userkeyMapping2 = [RKManagedObjectMapping mappingForClass:[Child2 class] inManagedObjectStore:manager.objectStore];
        [userkeyMapping2 mapKeyPath:@"uk" toAttribute:@"userID"];
        userkeyMapping2.primaryKeyAttribute = @"userID";
        [manager.mappingProvider setMapping:userkeyMapping2 forKeyPath:@"usk2"];

接続関係

[userkeyMapping1 hasOne:@"userDetail" withMapping:userDetailMapping];
        [userkeyMapping1 connectRelationship:@"userDetail" withObjectForPrimaryKeyAttribute:@"userID"];
        [userDetailMapping hasOne:@"userDetail1" withMapping:userkeyMapping1];
        [userDetailMapping connectRelationship:@"userDetail1" withObjectForPrimaryKeyAttribute:@"userID"];


[userkeyMapping2 hasOne:@"userDetail" withMapping:userDetailMapping];
        [userkeyMapping2 connectRelationship:@"userDetail" withObjectForPrimaryKeyAttribute:@"userID"];
        [userDetailMapping hasOne:@"userDetail2" withMapping:userkeyMapping2];
        [userDetailMapping connectRelationship:@"userDetail2" withObjectForPrimaryKeyAttribute:@"userID"];

Child1およびChild2のDBからオブジェクトを削除する

- (void)clearUserKeyTable {
    RKObjectManager *manager = [[RestKit sharedDataManager] objectManager];

    NSManagedObjectContext *context = [Child1 currentContext];

        NSArray *objects = [Child1 findAll];
        for (Child1 *object in objects) {
            [context deleteObject:object];
        }

        NSError *saveError = nil;
        [context save:&saveError];
        NIDPRINT(@"All records are deleted - %@", saveError);
        for (Child1 *object in objects) {
            [context refreshObject:object mergeChanges:NO];
        }
        [context save:&saveError];
        NIDPRINT(@"All records are deleted in Nearby- %@", saveError);
}

注:両方のビュー1は3分で自動的に更新されます。そのため、フェッチとマッピングの操作は画面に関係なく実行されます。

問題:VC1でページを手動で更新すると、クラッシュすることがあります。正確な理由はわかりません。My Simulatorでは、次のように表示されます

'NSObjectInaccessibleException', reason: 'CoreData could not fulfill a fault for '0x8a5b410 <x-coredata:/XXXX-XXXX-XXXX/Child1/p128>.

デバイスでデバッグすると、例外がスローされます。クラッシュログは次のとおりです。

Path:            /var/mobile/Applications/25FD9991-8134-476D-AADE-66D95BFC3C5B/MyApp.app/MyApp
Identifier:      MyApp
Version:         ??? (???)
Code Type:       ARM (Native)
Parent Process:  launchd [1]

Date/Time:       2013-02-25 23:17:27.645 -0600
OS Version:      iOS 6.0.1 (10A523)
Report Version:  104

Exception Type:  EXC_CRASH (SIGABRT)
Exception Codes: 0x0000000000000000, 0x0000000000000000
Crashed Thread:  10

Last Exception Backtrace:
0   CoreFoundation                  0x3147329e __exceptionPreprocess + 158
1   libobjc.A.dylib                 0x3233197a objc_exception_throw + 26
2   CoreData                        0x32741b38 _PFFaultHandlerLookupRow + 1472
3   CoreData                        0x327430fa _PF_FulfillDeferredFault + 198
4   CoreData                        0x3274ac0c _PF_ManagedObject_WillChangeValueForKeyIndex + 64
5   CoreData                        0x3275532e _sharedIMPL_setvfk_core + 106
6   CoreData                        0x327497c2 _PF_Handler_Public_SetProperty + 54
7   CoreData                        0x32750a4c -[NSManagedObject(_NSInternalMethods) _maintainInverseRelationship:forProperty:oldDestination:newDestination:] + 328
8   CoreData                        0x32751216 -[NSManagedObject(_NSInternalMethods) _didChangeValue:forRelationship:named:withInverse:] + 1286
9   CoreData                        0x3275a82e -[NSManagedObjectContext observeValueForKeyPath:ofObject:change:context:] + 318
10  Foundation                      0x32fd4eac NSKeyValueNotifyObserver + 268
11  Foundation                      0x32fd4b06 NSKeyValueDidChange + 330
12  Foundation                      0x32faeec6 -[NSObject(NSKeyValueObserverNotification) didChangeValueForKey:] + 90
13  CoreData                        0x3274ae26 _PF_ManagedObject_DidChangeValueForKeyIndex + 98
14  CoreData                        0x327553a2 _sharedIMPL_setvfk_core + 222
15  CoreData                        0x327497c2 _PF_Handler_Public_SetProperty + 54
16  CoreData                        0x32750ad6 -[NSManagedObject(_NSInternalMethods) _maintainInverseRelationship:forProperty:oldDestination:newDestination:] + 466
17  CoreData                        0x32751216 -[NSManagedObject(_NSInternalMethods) _didChangeValue:forRelationship:named:withInverse:] + 1286
18  CoreData                        0x3275a82e -[NSManagedObjectContext observeValueForKeyPath:ofObject:change:context:] + 318
19  Foundation                      0x32fd4eac NSKeyValueNotifyObserver + 268
20  Foundation                      0x32fd4b06 NSKeyValueDidChange + 330
21  Foundation                      0x32faeec6 -[NSObject(NSKeyValueObserverNotification) didChangeValueForKey:] + 90
22  CoreData                        0x3274ae26 _PF_ManagedObject_DidChangeValueForKeyIndex + 98
23  CoreData                        0x327553a2 _sharedIMPL_setvfk_core + 222
24  CoreData                        0x327497c2 _PF_Handler_Public_SetProperty + 54
25  CoreData                        0x3274bd1e -[NSManagedObject setValue:forKey:] + 86
26  Foundation                      0x32faf71e -[NSObject(NSKeyValueCoding) setValue:forKeyPath:] + 294
27  MyApp                       0x0019aa5c -[RKManagedObjectMappingOperation connectRelationship:] (RKManagedObjectMappingOperation.m:100)
28  MyApp                       0x0019af16 __55-[RKManagedObjectMappingOperation connectRelationships]_block_invoke_0 (RKManagedObjectMappingOperation.m:115)
29  Foundation                      0x32fdc534 -[NSBlockOperation main] + 196
30  Foundation                      0x32fd3db4 -[__NSOperationInternal start] + 836
31  MyApp                       0x001b063c -[RKMappingOperationQueue waitUntilAllOperationsAreFinished] (RKMappingOperationQueue.m:53)
32  MyApp                       0x001b6496 -[RKObjectMapper performMapping] (RKObjectMapper.m:368)
33  MyApp                       0x001b14f0 -[RKObjectLoader mapResponseWithMappingProvider:toObject:inContext:error:] (RKObjectLoader.m:227)
34  MyApp                       0x001b18c2 -[RKObjectLoader performMapping:] (RKObjectLoader.m:271)
35  MyApp                       0x001b1a9e __47-[RKObjectLoader performMappingInDispatchQueue]_block_invoke_0 (RKObjectLoader.m:282)
36  libdispatch.dylib               0x33a6311a _dispatch_call_block_and_release + 6
37  libdispatch.dylib               0x33a62996 _dispatch_queue_drain$VARIANT$up + 142
38  libdispatch.dylib               0x33a62890 _dispatch_queue_invoke$VARIANT$up + 32
39  libdispatch.dylib               0x33a71210 _dispatch_root_queue_drain + 188
40  libdispatch.dylib               0x33a713b4 _dispatch_worker_thread2 + 80
41  libsystem_c.dylib               0x33aa1a0c _pthread_wqthread + 356
42  libsystem_c.dylib               0x33aa18a0 start_wqthread + 4

スレッド10がクラッシュしました

Thread 10 name:  Dispatch queue: org.restkit.ObjectMapping
Thread 10 Crashed:
0   libsystem_kernel.dylib          0x30661350 __pthread_kill + 8
1   libsystem_c.dylib               0x33aca11e pthread_kill + 54
2   libsystem_c.dylib               0x33b0696e abort + 90
3   libc++abi.dylib                 0x314e7d4a abort_message + 70
4   libc++abi.dylib                 0x314e4ff4 _ZL17default_terminatev + 20
5   libobjc.A.dylib                 0x32331a74 _ZL15_objc_terminatev + 144
6   libc++abi.dylib                 0x314e5078 _ZL19safe_handler_callerPFvvE + 76
7   libc++abi.dylib                 0x314e5110 std::terminate() + 16
8   libc++abi.dylib                 0x314e6594 __cxa_rethrow + 84
9   libobjc.A.dylib                 0x323319cc objc_exception_rethrow + 8
10  CoreData                        0x32741f60 _PFFaultHandlerLookupRow + 2536
11  CoreData                        0x327430fa _PF_FulfillDeferredFault + 198
12  CoreData                        0x3274ac0c _PF_ManagedObject_WillChangeValueForKeyIndex + 64
13  CoreData                        0x3275532e _sharedIMPL_setvfk_core + 106
14  CoreData                        0x327497c2 _PF_Handler_Public_SetProperty + 54
15  CoreData                        0x32750a4c -[NSManagedObject(_NSInternalMethods) _maintainInverseRelationship:forProperty:oldDestination:newDestination:] + 328
16  CoreData                        0x32751216 -[NSManagedObject(_NSInternalMethods) _didChangeValue:forRelationship:named:withInverse:] + 1286
17  CoreData                        0x3275a82e -[NSManagedObjectContext observeValueForKeyPath:ofObject:change:context:] + 318
18  Foundation                      0x32fd4eac NSKeyValueNotifyObserver + 268
19  Foundation                      0x32fd4b06 NSKeyValueDidChange + 330
20  Foundation                      0x32faeec6 -[NSObject(NSKeyValueObserverNotification) didChangeValueForKey:] + 90
21  CoreData                        0x3274ae28 _PF_ManagedObject_DidChangeValueForKeyIndex + 100
22  CoreData                        0x327553a2 _sharedIMPL_setvfk_core + 222
23  CoreData                        0x327497c2 _PF_Handler_Public_SetProperty + 54
24  CoreData                        0x32750ad6 -[NSManagedObject(_NSInternalMethods) _maintainInverseRelationship:forProperty:oldDestination:newDestination:] + 466
25  CoreData                        0x32751216 -[NSManagedObject(_NSInternalMethods) _didChangeValue:forRelationship:named:withInverse:] + 1286
26  CoreData                        0x3275a82e -[NSManagedObjectContext observeValueForKeyPath:ofObject:change:context:] + 318
27  Foundation                      0x32fd4eac NSKeyValueNotifyObserver + 268
28  Foundation                      0x32fd4b06 NSKeyValueDidChange + 330
29  Foundation                      0x32faeec6 -[NSObject(NSKeyValueObserverNotification) didChangeValueForKey:] + 90
30  CoreData                        0x3274ae28 _PF_ManagedObject_DidChangeValueForKeyIndex + 100
31  CoreData                        0x327553a2 _sharedIMPL_setvfk_core + 222
32  CoreData                        0x327497c2 _PF_Handler_Public_SetProperty + 54
33  CoreData                        0x3274bd1e -[NSManagedObject setValue:forKey:] + 86
34  Foundation                      0x32faf71e -[NSObject(NSKeyValueCoding) setValue:forKeyPath:] + 294
35  MyApp                       0x0019aa5c -[RKManagedObjectMappingOperation connectRelationship:] (RKManagedObjectMappingOperation.m:100)
36  MyApp                       0x0019af16 __55-[RKManagedObjectMappingOperation connectRelationships]_block_invoke_0 (RKManagedObjectMappingOperation.m:115)
37  Foundation                      0x32fdc536 -[NSBlockOperation main] + 198
38  Foundation                      0x32fd3db4 -[__NSOperationInternal start] + 836
39  MyApp                       0x001b063c -[RKMappingOperationQueue waitUntilAllOperationsAreFinished] (RKMappingOperationQueue.m:53)
40  MyApp                       0x001b6496 -[RKObjectMapper performMapping] (RKObjectMapper.m:368)
41  MyApp                       0x001b14f0 -[RKObjectLoader mapResponseWithMappingProvider:toObject:inContext:error:] (RKObjectLoader.m:227)
42  MyApp                       0x001b18c2 -[RKObjectLoader performMapping:] (RKObjectLoader.m:271)
43  MyApp                       0x001b1a9e __47-[RKObjectLoader performMappingInDispatchQueue]_block_invoke_0 (RKObjectLoader.m:282)
44  libdispatch.dylib               0x33a6311c _dispatch_call_block_and_release + 8
45  libdispatch.dylib               0x33a62996 _dispatch_queue_drain$VARIANT$up + 142
46  libdispatch.dylib               0x33a62890 _dispatch_queue_invoke$VARIANT$up + 32
47  libdispatch.dylib               0x33a71212 _dispatch_root_queue_drain + 190
48  libdispatch.dylib               0x33a713b4 _dispatch_worker_thread2 + 80
49  libsystem_c.dylib               0x33aa1a0e _pthread_wqthread + 358
50  libsystem_c.dylib               0x33aa18a0 start_wqthread + 4

ありがとう

4

2 に答える 2