我在我的项目中使用Core Data,现在我想添加同步功能。滚动我自己变得比我想象的更难;因此,我想尝试准备好的库。
我在项目中集成了Couchbase,为同步网关和服务器设置了IBM Cloudant。
对于一个非常简单的项目,我测试了它,一切似乎都运行正常。但是,当我对现有项目实施相同的解决方案时;它有时会崩溃,我不知道如何解决这个问题。
P.S。信息是否有所不同:由于核心数据一直在抱怨它不能修改不可变模型,因此我对CBLIncrementStore中的模型更新感到很遗憾。虽然事件没有被使用或附加到持久性商店。最后,我不得不创建一个新项目,修改模型,并将模型复制到我现有的项目中。然后它开始工作了。甚至低于代码,返回模型的mutableCopy;没有工作(事件虽然它在一个空项目中完美运行):
编辑 - 通常情况下,不需要返回mutableCopy这是我在特定情况下尝试过的。上面解释^^
// MARK: - MODEL
lazy var modelURL: URL = {
let bundle = Bundle.main
if let url = bundle.url(forResource: "couchsync", withExtension: "momd") {
return url
}
DLog("CRITICAL - Managed Object Model file not found")
abort()
}()
lazy var model: NSManagedObjectModel = {
if let mutableModel = NSManagedObjectModel(contentsOf: self.modelURL)?.mutableCopy() as? NSManagedObjectModel {
return mutableModel
}
DLog("CRITICAL - Can't read model")
abort()
}()
代码在CBLIncrementalStore中崩溃:
- (NSIncrementalStoreNode*) newValuesForObjectWithID: (NSManagedObjectID*)objectID
withContext: (NSManagedObjectContext*)context
error: (NSError**)outError {
调试输出如下(CDStack.swift来自我的项目):
[00324]:CDStack.swift :save.......................... :16:15:14 Inserted objects count = 33
2017-04-11 16:15:14.132 MuhApp[23391:1022666] -[__NSCFNumber _fastCStringContents:]: unrecognized selector sent to instance 0xb000000000000001
2017-04-11 16:15:14.142 MuhApp[23391:1022666] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFNumber _fastCStringContents:]: unrecognized selector sent to instance 0xb000000000000001'
*** First throw call stack:
(
0 CoreFoundation 0x000000010c6e3b0b __exceptionPreprocess + 171
1 libobjc.A.dylib 0x000000010bba0141 objc_exception_throw + 48
2 CoreFoundation 0x000000010c753134 -[NSObject(NSObject) doesNotRecognizeSelector:] + 132
3 CoreFoundation 0x000000010c66a840 ___forwarding___ + 1024
4 CoreFoundation 0x000000010c66a3b8 _CF_forwarding_prep_0 + 120
5 CoreData 0x000000010c1e9cfd _PFRawFastIndexForKnownKey + 93
6 CoreData 0x000000010c1e9bfe _PFRawIndexForKnownKey + 62
7 CoreData 0x000000010c1ea49c -[NSKnownKeysDictionary1 objectForKey:] + 28
8 MuhApp 0x000000010a184639 __66-[CBLIncrementalStore newValuesForObjectWithID:withContext:error:]_block_invoke_2 + 121
9 CoreData 0x000000010c239b52 developerSubmittedBlockToNSManagedObjectContextPerform + 178
10 CoreData 0x000000010c239a1f -[NSManagedObjectContext performBlockAndWait:] + 239
11 MuhApp 0x000000010a18449e __66-[CBLIncrementalStore newValuesForObjectWithID:withContext:error:]_block_invoke + 670
12 libdispatch.dylib 0x000000011351405c _dispatch_client_callout + 8
13 libdispatch.dylib 0x00000001134f1de6 _dispatch_barrier_sync_f_invoke + 346
14 MuhApp 0x000000010a184033 -[CBLIncrementalStore newValuesForObjectWithID:withContext:error:] + 403
15 CoreData 0x000000010c2ea624 __95-[NSPersistentStoreCoordinator(_NSInternalMethods) newValuesForObjectWithID:withContext:error:]_block_invoke + 100
16 CoreData 0x000000010c2f32f4 gutsOfBlockToNSPersistentStoreCoordinatorPerform + 196
17 libdispatch.dylib 0x000000011351405c _dispatch_client_callout + 8
18 libdispatch.dylib 0x00000001134f1de6 _dispatch_barrier_sync_f_invoke + 346
19 CoreData 0x000000010c2e0785 _perform + 213
20 CoreData 0x000000010c2e0505 -[NSPersistentStoreCoordinator _routeLightweightBlock:toStore:] + 229
21 CoreData 0x000000010c211d01 -[NSPersistentStoreCoordinator(_NSInternalMethods) newValuesForObjectWithID:withContext:error:] + 417
22 CoreData 0x000000010c211218 _PFFaultHandlerLookupRow + 376
23 CoreData 0x000000010c210c9f _PF_FulfillDeferredFault + 239
24 CoreData 0x000000010c2341e2 -[NSManagedObject(_NSInternalMethods) _includeObject:intoPropertyWithKey:andIndex:] + 130
25 CoreData 0x000000010c2339c0 -[NSManagedObject(_NSInternalMethods) _didChangeValue:forRelationship:named:withInverse:] + 576
26 Foundation 0x000000010b6a96dc NSKeyValueNotifyObserver + 351
27 Foundation 0x000000010b6a8f93 NSKeyValueDidChange + 484
28 Foundation 0x000000010b679709 -[NSObject(NSKeyValueObserverNotification) didChangeValueForKey:] + 111
29 CoreData 0x000000010c21c40d -[NSManagedObject didChangeValueForKey:] + 93
30 CoreData 0x000000010c2a773f -[NSManagedObject(_NSInternalMethods) _updateFromRefreshSnapshot:includingTransients:] + 799
31 CoreData 0x000000010c23fe54 -[NSManagedObjectContext(_NestedContextSupport) _copyChildObject:toParentObject:fromChildContext:] + 948
32 CoreData 0x000000010c23f413 -[NSManagedObjectContext(_NestedContextSupport) _parentProcessSaveRequest:inContext:error:] + 947
33 CoreData 0x000000010c2ba927 __82-[NSManagedObjectContext(_NestedContextSupport) executeRequest:withContext:error:]_block_invoke + 567
34 CoreData 0x000000010c23a0ea internalBlockToNSManagedObjectContextPerform + 106
35 libdispatch.dylib 0x000000011351405c _dispatch_client_callout + 8
36 libdispatch.dylib 0x00000001134f1de6 _dispatch_barrier_sync_f_invoke + 346
37 CoreData 0x000000010c23a054 _perform + 244
38 CoreData 0x000000010c239e7d -[NSManagedObjectContext(_NestedContextSupport) executeRequest:withContext:error:] + 301
39 CoreData 0x000000010c221488 -[NSManagedObjectContext save:] + 3368
40 MuhApp 0x000000010a215522 _TFZFC6MuhApp7CDStack4saveFCSo22NSManagedObjectContextT_U_FT_T_ + 610
41 MuhApp 0x000000010a1a0927 _TTRXFo___XFdCb___ + 39
42 CoreData 0x000000010c239b52 developerSubmittedBlockToNSManagedObjectContextPerform + 178
43 CoreData 0x000000010c239a1f -[NSManagedObjectContext performBlockAndWait:] + 239
44 MuhApp 0x000000010a21529b _TZFC6MuhApp7CDStack4savefCSo22NSManagedObjectContextT_ + 187
45 MuhApp 0x000000010a1ded49 _TFC6MuhApp7MUStoreP33_5810EFAD2D482DA23D84CA4C96F2558221createbusinessFoldersfT_GSaCS_9MUAccount_ + 11145
46 MuhApp 0x000000010a1db875 _TFC6MuhApp7MUStoreP33_5810EFAD2D482DA23D84CA4C96F2558228fetchOrCreateBusinessFoldersfT_GSaCS_9MUAccount_ + 133
47 MuhApp 0x000000010a1d4e78 _TFC6MuhApp7MUStoreg15businessFoldersGSaCS_9MUAccount_ + 120
48 MuhApp 0x000000010a236fa0 _TFC6MuhApp23MainTableViewController7preparefT3forCSo17UIStoryboardSegue6senderGSqP___T_ + 1088
49 MuhApp 0x000000010a2380fb _TToFC6MuhApp23MainTableViewController7preparefT3forCSo17UIStoryboardSegue6senderGSqP___T_ + 187
50 UIKit 0x000000010dc158ee -[UIStoryboardSegueTemplate _performWithDestinationViewController:sender:] + 353
51 UIKit 0x000000010dc1575c -[UIStoryboardSegueTemplate _perform:] + 82
52 UIKit 0x000000010dc15a1f -[UIStoryboardSegueTemplate perform:] + 157
53 UIKit 0x000000010d5a4d77 -[UITableView _selectRowAtIndexPath:animated:scrollPosition:notifyDelegate:] + 1677
54 UIKit 0x000000010d5a4fe3 -[UITableView _userSelectRowAtPendingSelectionIndexPath:] + 344
55 UIKit 0x000000010d45a7f3 _runAfterCACommitDeferredBlocks + 318
56 UIKit 0x000000010d4477bc _cleanUpAfterCAFlushAndRunDeferredBlocks + 532
57 UIKit 0x000000010d47928c _afterCACommitHandler + 137
58 CoreFoundation 0x000000010c689717 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 23
59 CoreFoundation 0x000000010c689687 __CFRunLoopDoObservers + 391
60 CoreFoundation 0x000000010c66e720 __CFRunLoopRun + 1200
61 CoreFoundation 0x000000010c66e016 CFRunLoopRunSpecific + 406
62 GraphicsServices 0x0000000110359a24 GSEventRunModal + 62
63 UIKit 0x000000010d44e0d4 UIApplicationMain + 159
64 MuhApp 0x000000010a2a9da7 main + 55
65 libdyld.dylib 0x000000011356065d start + 1
66 ??? 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
任何想法如何从这里开始?