- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我正在为我的应用程序使用 restkit 0.10.2。我有不同的表,其中数据从服务器获取并存储到数据库中。
我有三张表,一张主表和两张子表。两个子表都与主表是一对一的关系。
我有两个不同的 View Controller V1 和 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 的对象
- (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);
}
注意:两个 View 1 都会在 3 分钟后自动刷新。因此无论屏幕如何,抓取和映射操作都会执行。
问题:有时我在VC1中手动刷新页面时,它会崩溃。我不知道确切的原因。在我的模拟器中,它显示为
'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
谢谢
最佳答案
问题似乎是您正在尝试刷新已删除的对象。问题导致这段代码:
for (Child1 *object in objects) {
[context refreshObject:object mergeChanges:NO];
}
[context save:&saveError];
NIDPRINT(@"All records are deleted in Nearby- %@", saveError);
关于iphone - 应用程序在使用 Restkit for IOS 进行对象映射期间意外崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15083133/
我正在通过 labrepl 工作,我看到了一些遵循此模式的代码: ;; Pattern (apply #(apply f %&) coll) ;; Concrete example user=> (a
我从未向应用商店提交过应用,但我会在不久的将来提交。 到目前为止,我对为 iPhone 而非 iPad 进行设计感到很自在。 我了解,通过将通用PAID 应用放到应用商店,客户只需支付一次就可以同时使
我有一个应用程序,它使用不同的 Facebook 应用程序(2 个不同的 AppID)在 Facebook 上发布并显示它是“通过 iPhone”/“通过 iPad”。 当 Facebook 应用程序
我有一个要求,我们必须通过将网站源文件保存在本地 iOS 应用程序中来在 iOS 应用程序 Webview 中运行网站。 Angular 需要服务器来运行应用程序,但由于我们将文件保存在本地,我们无法
所以我有一个单页客户端应用程序。 正常流程: 应用程序 -> OAuth2 服务器 -> 应用程序 我们有自己的 OAuth2 服务器,因此人们可以登录应用程序并获取与用户实体关联的 access_t
假设我有一个安装在用户设备上的 Android 应用程序 A,我的应用程序有一个 AppWidget,我们可以让其他 Android 开发人员在其中以每次安装成本为基础发布他们的应用程序推广广告。因此
Secrets of the JavaScript Ninja中有一个例子它提供了以下代码来绕过 JavaScript 的 Math.min() 函数,该函数需要一个可变长度列表。 Example:
当我分别将数组和对象传递给 function.apply() 时,我得到 NaN 的 o/p,但是当我传递对象和数组时,我得到一个数字。为什么会发生这种情况? 由于数组也被视为对象,为什么我无法使用它
CFSDN坚持开源创造价值,我们致力于搭建一个资源共享平台,让每一个IT人在这里找到属于你的精彩世界. 这篇CFSDN的博客文章ASP转换格林威治时间函数DateDiff()应用由作者收集整理,如果你
我正在将列表传递给 map并且想要返回一个带有合并名称的 data.frame 对象。 例如: library(tidyverse) library(broom) mtcars %>% spl
我有一个非常基本的问题,但我不知道如何实现它:我有一个返回数据框,其中每个工具的返回值是按行排列的: tmp<-as.data.frame(t(data.frame(a=rnorm(250,0,1)
我正在使用我的 FB 应用创建群组并邀请用户加入我的应用群组,第一次一切正常。当我尝试创建另一个组时,出现以下错误: {"(OAuthException - #4009) (#4009) 在有更多用户
我们正在开发一款类似于“会说话的本”应用程序的 child 应用程序。它包含大量用于交互式动画的 JPEG 图像序列。 问题是动画在 iPad Air 上播放正常,但在 iPad 2 上播放缓慢或滞后
我关注 clojure 一段时间了,它的一些功能非常令人兴奋(持久数据结构、函数式方法、不可变状态)。然而,由于我仍在学习,我想了解如何在实际场景中应用,证明其好处,然后演化并应用于更复杂的问题。即,
我开发了一个仅使用挪威语的应用程序。该应用程序不使用本地化,因为它应该仅以一种语言(挪威语)显示。但是,我已在 Info.plist 文件中将“本地化 native 开发区域”设置为“no”。我还使用
读完 Anthony's response 后上a style-related parser question ,我试图说服自己编写单体解析器仍然可以相当紧凑。 所以而不是 reference ::
multicore 库中是否有类似 sapply 的东西?还是我必须 unlist(mclapply(..)) 才能实现这一点? 如果它不存在:推理是什么? 提前致谢,如果这是一个愚蠢的问题,我们深表
我喜欢在窗口中弹出结果,以便更容易查看和查找(例如,它们不会随着控制台继续滚动而丢失)。一种方法是使用 sink() 和 file.show()。例如: y <- rnorm(100); x <- r
我有一个如下所示的 spring mvc Controller @RequestMapping(value="/new", method=RequestMethod.POST) public Stri
我正在阅读 StructureMap关于依赖注入(inject),首先有两部分初始化映射,具体类类型的接口(interface),另一部分只是实例化(请求实例)。 第一部分需要配置和设置,这是在 Bo
我是一名优秀的程序员,十分优秀!