I am using Core Data in my project and now I wanted to add sync features. Rolling my own turned out to be harder than I thought; therefore, I wanted to try ready libraries.
I integrated Couchbase in the project, setup IBM Cloudant for sync gateway and server.
For a very simple project I tested it and everything seems to be working fine. However, when I implement the same solution to the existing project; it crashes sometimes and I don't have the slightest clue how to approach the problem.
p.s. Info if it makes a difference: I had hell of a time with the model update in CBLIncrementStore as the core data kept complaining that it can't modify an immutable model; event though it was not used or attached to persistent store. In the end I had to create a new project, modified the model, and copy the model to my existing project. Then it started working. Even below code, where returning an mutableCopy of the model; didn't work (event though it worked perfectly in an empty project):
EDIT - Normally, no need to return mutableCopy this is something I tried in my particular case. Explained above^^
// 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()
}()
The code crashes below in CBLIncrementalStore:
- (NSIncrementalStoreNode*) newValuesForObjectWithID: (NSManagedObjectID*)objectID
withContext: (NSManagedObjectContext*)context
error: (NSError**)outError {
And the debug output is as follows (CDStack.swift is from my project):
[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)
Any ideas how to proceed from here?
Related
I am calling a function through another view controller with:
perform(#selector(MainScreenViewController().test))
The action is called test and it is located in the MainScreenViewController().
Once it reaches this code the application crashes with the following crash report:
2018-01-20 13:24:46.800692+0100 Business Name[40750:3947268] -[Business_Name.RPLabel test]: unrecognized selector sent to instance 0x7fd444d03e30
2018-01-20 13:24:46.809915+0100 Business Name[40750:3947268] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[Business_Name.RPLabel test]: unrecognized selector sent to instance 0x7fd444d03e30'
*** First throw call stack:
(
0 CoreFoundation 0x00000001127621cb __exceptionPreprocess + 171
1 libobjc.A.dylib 0x000000010de9af41 objc_exception_throw + 48
2 CoreFoundation 0x00000001127e2914 -[NSObject(NSObject) doesNotRecognizeSelector:] + 132
3 UIKit 0x000000010f5810bd -[UIResponder doesNotRecognizeSelector:] + 295
4 CoreFoundation 0x00000001126e5178 ___forwarding___ + 1432
5 CoreFoundation 0x00000001126e4b58 _CF_forwarding_prep_0 + 120
6 Business Name 0x000000010d54edc2 _T013Business_Name7RPLabelC5setupyyF + 738
7 Business Name 0x000000010d54e705 _T013Business_Name7RPLabelCACSC6CGRectV5frame_tcfc + 325
8 Business Name 0x000000010d54e746 _T013Business_Name7RPLabelCACSC6CGRectV5frame_tcfcTo + 38
9 UIKit 0x000000010f3f3f66 -[UIView init] + 62
10 Business Name 0x000000010d5385a3 _T0So7UILabelCABycfcTO + 19
11 Business Name 0x000000010d53137c _T0So7UILabelCABycfC + 60
12 Business Name 0x000000010d538944 globalinit_33_2857E66F75A5DBE934F5CCD1167A060E_func5 + 20
13 libdispatch.dylib 0x000000011380f43c _dispatch_client_callout + 8
14 libdispatch.dylib 0x00000001138109c7 dispatch_once_f + 297
15 Business Name 0x000000010d538984 _T013Business_Name9mainTitleAA7RPLabelCfau + 36
16 Business Name 0x000000010d5389ae _T013Business_Name10setupTitleyyF + 30
17 Business Name 0x000000010d53fd1f _T013Business_Name24MainScreenViewControllerC13viewDidAppearySbF + 31
18 Business Name 0x000000010d53fe23 _T013Business_Name24MainScreenViewControllerC13viewDidAppearySbFTo + 51
19 UIKit 0x000000010f4fcaaf -[UIViewController _setViewAppearState:isAnimating:] + 699
20 UIKit 0x000000010f55b746 -[UITabBarController viewDidAppear:] + 115
21 UIKit 0x000000010f4fcaaf -[UIViewController _setViewAppearState:isAnimating:] + 699
22 UIKit 0x000000010f4ff959 __64-[UIViewController viewDidMoveToWindow:shouldAppearOrDisappear:]_block_invoke + 42
23 UIKit 0x000000010f4fdc4d -[UIViewController _executeAfterAppearanceBlock] + 86
24 UIKit 0x000000010f364d9d _runAfterCACommitDeferredBlocks + 634
25 UIKit 0x000000010f35330d _cleanUpAfterCAFlushAndRunDeferredBlocks + 280
26 UIKit 0x000000010f374714 __34-[UIApplication _firstCommitBlock]_block_invoke_2 + 155
27 CoreFoundation 0x000000011270520c __CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK__ + 12
28 CoreFoundation 0x00000001126e9a3b __CFRunLoopDoBlocks + 203
29 CoreFoundation 0x00000001126e9214 __CFRunLoopRun + 1300
30 CoreFoundation 0x00000001126e8a89 CFRunLoopRunSpecific + 409
31 GraphicsServices 0x000000011556e9c6 GSEventRunModal + 62
32 UIKit 0x000000010f358d30 UIApplicationMain + 159
33 Business Name 0x000000010d548637 main + 55
34 libdyld.dylib 0x000000011388bd81 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
This is the code in test:
#objc func test(){
print("test")
}
MainScreenViewController().perform(#selector(MainScreenViewController().test))
I am keep getting this error for NSFetchedResultsControllerDelegate.
not sure what to do with it, since it happen sporadically.
I do create the records synchronized, but still ..
any ideas why could this be?
- (Activity *)createActivityWithDictionary:(NSDictionary*)dict
{
#synchronized([DBController sharedManaged])
{
Activity *act = [Activity activityWithDictionary:dict inManagedObjectContext:self.managedObjectContext];
[self saveContext];
return act;
}
}
Date/Time: 2012-09-18 22:55:53.686 -0700
OS Version: iPhone OS 5.1.1 (9B206)
Report Version: 104
Exception Type: EXC_CRASH (SIGABRT)
Exception Codes: 0x00000000, 0x00000000
Crashed Thread: 0
Last Exception Backtrace:
0 CoreFoundation 0x3724188f __exceptionPreprocess + 163
1 libobjc.A.dylib 0x34f46259 objc_exception_throw + 33
2 CoreFoundation 0x37244a9b -[NSObject doesNotRecognizeSelector:] + 175
3 CoreFoundation 0x37243915 ___forwarding___ + 301
4 CoreFoundation 0x3719e650 _CF_forwarding_prep_0 + 48
5 CoreData 0x36a78f4d -[NSFetchedResultsController(PrivateMethods) _managedObjectContextDidChange:] + 2401
6 Foundation 0x37aa64ff __57-[NSNotificationCenter addObserver:selector:name:object:]_block_invoke_0 + 19
7 CoreFoundation 0x3720d547 ___CFXNotificationPost_block_invoke_0 + 71
8 CoreFoundation 0x37199097 _CFXNotificationPost + 1407
9 Foundation 0x37a1a3eb -[NSNotificationCenter postNotificationName:object:userInfo:] + 67
10 CoreData 0x36a00839 -[NSManagedObjectContext(_NSInternalNotificationHandling) _postObjectsDidChangeNotificationWithUserInfo:] + 77
11 CoreData 0x36a0031d -[NSManagedObjectContext(_NSInternalChangeProcessing) _createAndPostChangeNotification:withDeletions:withUpdates:withRefreshes:] + 305
12 CoreData 0x36a09d01 -[NSManagedObjectContext(_NSInternalChangeProcessing) _processRecentChanges:] + 1245
13 CoreData 0x369fd145 -[NSManagedObjectContext save:] + 201
14 PalFinds 0x000a57cb -[DBController saveContext] (DBController.m:75)
15 PalFinds 0x000a8dff -[DBController createActivityWithDictionaries:] (DBController.m:852)
16 PalFinds 0x00086649 -[PFMe finishRequest:andRestConnection:] (PFMe.m:1986)
17 PalFinds 0x0002e17d -[RestConnection connectionDidFinishLoading:] (RestConnection.m:326)
18 Foundation 0x37addc29 __65-[NSURLConnectionInternal _withConnectionAndDelegate:onlyActive:]_block_invoke_0 + 17
19 Foundation 0x37a356d9 -[NSURLConnectionInternalConnection invokeForDelegate:] + 29
20 Foundation 0x37a356a3 -[NSURLConnectionInternal _withConnectionAndDelegate:onlyActive:] + 199
21 Foundation 0x37a355c5 -[NSURLConnectionInternal _withActiveConnectionAndDelegate:] + 61
22 CFNetwork 0x36ed97f5 URLConnectionClient::_clientDidFinishLoading(URLConnectionClient::ClientConnectionEventQueue*) + 193
23 CFNetwork 0x36ece4a5 URLConnectionClient::ClientConnectionEventQueue::processAllEventsAndConsumePayload(XConnectionEventInfo<XClientEvent, XClientEventParams>*, long) + 425
24 CFNetwork 0x36ece599 URLConnectionClient::ClientConnectionEventQueue::processAllEventsAndConsumePayload(XConnectionEventInfo<XClientEvent, XClientEventParams>*, long) + 669
25 CFNetwork 0x36ece599 URLConnectionClient::ClientConnectionEventQueue::processAllEventsAndConsumePayload(XConnectionEventInfo<XClientEvent, XClientEventParams>*, long) + 669
26 CFNetwork 0x36ece1a3 URLConnectionClient::processEvents() + 107
27 CFNetwork 0x36ece0d9 MultiplexerSource::perform() + 157
28 CoreFoundation 0x37215ad3 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 15
29 CoreFoundation 0x3721529f __CFRunLoopDoSources0 + 215
30 CoreFoundation 0x37214045 __CFRunLoopRun + 653
31 CoreFoundation 0x371974a5 CFRunLoopRunSpecific + 301
32 CoreFoundation 0x3719736d CFRunLoopRunInMode + 105
33 GraphicsServices 0x33956439 GSEventRunModal + 137
34 UIKit 0x30f43cd5 UIApplicationMain + 1081
35 PalFinds 0x000038bf main (main.mm:14)
36 PalFinds 0x00003878 start + 40
Looks like it's trying to call the delegate back and the delegate isn't implementing a method it's supposed to.
I'm thinking either controller:didChangeObject:atIndexPath:forChangeType:newIndexPath: or controllerDidChangeContent:
Did you implement those methods in your NSFetchedResultsControllerDelegate?
I know this might seem far fetched BUT I had a very similar problem and I had all those methods implemented and then I realized I had my release commented out for the fetchedREsultsController...once I put that back in no more sigbart and works like a charm.
All I'm saying is that sometimes the error isn't always the obvious.
We would need to see a bit more code to figure it out. Thanks.
I'm getting a strange error with core data. Sometimes, but not all the time my app will crash when I try to access a core data object.
It happens regularly on iPhone 3's and only sometimes on iPhone 4's. I looked at my device log and narrowed it down to an issue with core data. The line the logs refer to is below, tripInstructor is a core data object, its a property of the AppManager class. Not sure if this makes a big difference but I do declare the property as being "nonatomic, retain".
Thanks for any advice
[self.supervisorLbl setText:[AppManager sharedAppManager].tripInstructor.name];
Date/Time: 2011-06-12 20:55:24.865 +1000
OS Version: iPhone OS 4.3.3 (8J2)
Report Version: 104
Exception Type: EXC_CRASH (SIGABRT)
Exception Codes: 0x00000000, 0x00000000
Crashed Thread: 0
Thread 0 name: Dispatch queue: com.apple.main-thread
Thread 0 Crashed:
0 libsystem_kernel.dylib 0x33e8da1c pthread_kill + 8
1 libsystem_c.dylib 0x35e5b3b4 pthread_kill + 52
2 libsystem_c.dylib 0x35e53bf8 abort + 72
3 libstdc++.6.dylib 0x33508a64 __gnu_cxx::__verbose_terminate_handler() + 376
4 libobjc.A.dylib 0x33f1106c _objc_terminate + 104
5 libstdc++.6.dylib 0x33506e36 _cxxabiv1::_terminate(void (*)()) + 46
6 libstdc++.6.dylib 0x33506e8a std::terminate() + 10
7 libstdc++.6.dylib 0x33506efe __cxa_rethrow + 62
8 libobjc.A.dylib 0x33f10fd8 objc_exception_rethrow + 4
9 CoreData 0x35624f66 _PFFaultHandlerLookupRow + 1450
10 CoreData 0x356799ba -[NSFaultHandler fulfillFault:withContext:] + 14
11 CoreData 0x35678782 _PF_FulfillDeferredFault + 354
12 CoreData 0x35623f18 _sharedIMPL_pvfk_core + 52
13 CoreData 0x35626b68 _pvfk_5 + 4
14 eLogger 0x0000e346 -[VicLogVC viewWillAppear:] (VicLogVC.m:207)
15 UIKit 0x3636bf14 -[UINavigationController _startTransition:fromViewController:toViewController:] + 604
16 UIKit 0x3636bc3c -[UINavigationController _startDeferredTransitionIfNeeded] + 176
17 UIKit 0x3635dd56 -[UINavigationController pushViewController:transition:forceImmediate:] + 634
18 UIKit 0x3635dacc -[UINavigationController pushViewController:animated:] + 28
19 eLogger 0x00025332 -[TripScreenVC _populateAndDisplayVicLog] (TripScreenVC.m:221)
20 eLogger 0x00025492 -[TripScreenVC _determineLogScreen] (TripScreenVC.m:258)
21 eLogger 0x000255d4 -[TripScreenVC buttonPressed:] (TripScreenVC.m:307)
22 CoreFoundation 0x30d4356a -[NSObject(NSObject) performSelector:withObject:withObject:] + 18
23 UIKit 0x36343ec2 -[UIApplication sendAction:to:from:forEvent:] + 78
24 UIKit 0x36343e62 -[UIApplication sendAction:toTarget:fromSender:forEvent:] + 26
25 UIKit 0x36343e34 -[UIControl sendAction:to:forEvent:] + 32
26 UIKit 0x36343b86 -[UIControl(Internal) _sendActionsForEvents:withEvent:] + 350
27 UIKit 0x3634441c -[UIControl touchesEnded:withEvent:] + 336
28 UIKit 0x36342bee -[UIWindow _sendTouchesForEvent:] + 362
29 UIKit 0x36342568 -[UIWindow sendEvent:] + 256
30 UIKit 0x3632b30c -[UIApplication sendEvent:] + 292
31 UIKit 0x3632ac4c _UIApplicationHandleEvent + 5084
32 GraphicsServices 0x34e2be70 PurpleEventCallback + 660
33 CoreFoundation 0x30daaa90 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION + 20
34 CoreFoundation 0x30dac838 __CFRunLoopDoSource1 + 160
35 CoreFoundation 0x30dad606 __CFRunLoopRun + 514
36 CoreFoundation 0x30d3debc CFRunLoopRunSpecific + 224
37 CoreFoundation 0x30d3ddc4 CFRunLoopRunInMode + 52
38 GraphicsServices 0x34e2b418 GSEventRunModal + 108
39 GraphicsServices 0x34e2b4c4 GSEventRun + 56
40 UIKit 0x36355d62 -[UIApplication _run] + 398
41 UIKit 0x36353800 UIApplicationMain + 664
42 eLogger 0x00002ff8 main (main.m:14)
43 eLogger 0x00002fa0 start + 32
You are likely holding on to an invalid reference to a managed object, it looks like it was turned into a fault by the managed object context, perhaps after calling -save: or -reset on the context.
If you deleted an object from your store, and still held a reference to the managed object in the ivar then that could be the cause of this error. The object will be deleted by CoreData and turned into a fault when -save: is called (at which point you should nil and reset your ivars). But, when you try to fault the object (by accessing one or more of it's properties) it won't be found in the store because you deleted it.
NSError *error;
if (managedObjectContext != nil) {
if ([managedObjectContext hasChanges] && ![managedObjectContext save:&error]) {
DLog(#"Unresolved error %#, %#", error, [error userInfo]);
abort();
}
}
while saving some items with the above code in CoreDate i get the following exception. the managedObjectContext has 50 unresolved deletes and 700 unresolved insertions. obviously its having a problem with the deletes. any ideas on how to track it down?
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSSet0 removeObject:]: unrecognized selector sent to instance 0x61a4840'
*** Call stack at first throw:
(
0 CoreFoundation 0x018d45a9 __exceptionPreprocess + 185
1 libobjc.A.dylib 0x01a28313 objc_exception_throw + 44
2 CoreFoundation 0x018d60bb -[NSObject(NSObject) doesNotRecognizeSelector:] + 187
3 CoreFoundation 0x01845966 ___forwarding___ + 966
4 CoreFoundation 0x01845522 _CF_forwarding_prep_0 + 50
5 CoreData 0x00ffa31d -[NSManagedObject(_NSInternalMethods) _excludeObject:fromPropertyWithKey:andIndex:] + 397
6 CoreData 0x00fef7d1 -[NSManagedObject(_NSInternalMethods) _maintainInverseRelationship:forProperty:oldDestination:newDestination:] + 449
7 CoreData 0x01043b55 -[NSManagedObject(_NSInternalMethods) _propagateDelete:] + 1541
8 CoreData 0x00ffa02a -[NSManagedObject(_NSInternalMethods) _propagateDelete] + 42
9 CoreData 0x00ff9e53 -[NSManagedObjectContext(_NSInternalChangeProcessing) _propagateDeletesUsingTable:] + 515
10 CoreData 0x00ff9c12 -[NSManagedObjectContext(_NSInternalChangeProcessing) _processDeletedObjects:] + 146
11 CoreData 0x00fecba8 -[NSManagedObjectContext(_NSInternalChangeProcessing) _propagatePendingDeletesAtEndOfEvent:] + 104
12 CoreData 0x00fb8982 -[NSManagedObjectContext(_NSInternalChangeProcessing) _processRecentChanges:] + 754
13 CoreData 0x00ff2715 -[NSManagedObjectContext save:] + 149
14 Ace Metrix iPad 0x00075153 +[CoreDataHelper saveCoreDate:] + 82
15 Ace Metrix iPad 0x0007a790 -[WSBreakingAds platformRequestFinishedWhidType:withResponse:] + 772
16 Ace Metrix iPad 0x00077c6d -[PlatformContainer operation:completedWithResponse:withNSManagedObjectContext:] + 1042
17 Ace Metrix iPad 0x000401ec -[WebServiceAuthServiceSoapBinding_getPartialAdvertisementsAfterDate connectionDidFinishLoading:] + 1209
18 Foundation 0x00182112 -[NSURLConnection(NSURLConnectionReallyInternal) sendDidFinishLoading] + 108
19 Foundation 0x0018206b _NSURLConnectionDidFinishLoading + 133
20 CFNetwork 0x00dec492 _ZN19URLConnectionClient23_clientDidFinishLoadingEPNS_26ClientConnectionEventQueueE + 220
21 CFNetwork 0x00eb76e1 _ZN19URLConnectionClient26ClientConnectionEventQueue33processAllEventsAndConsumePayloadEP20XConnectionEventInfoI12XClientEvent18XClientEventParamsEl + 293
22 CFNetwork 0x00de2c84 _ZN19URLConnectionClient13processEventsEv + 100
23 CFNetwork 0x00de2ad3 _ZN17MultiplexerSource7performEv + 251
24 CoreFoundation 0x018b58ff __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 15
25 CoreFoundation 0x0181388b __CFRunLoopDoSources0 + 571
26 CoreFoundation 0x01812d86 __CFRunLoopRun + 470
27 CoreFoundation 0x01812840 CFRunLoopRunSpecific + 208
28 CoreFoundation 0x01812761 CFRunLoopRunInMode + 97
29 GraphicsServices 0x01e3e1c4 GSEventRunModal + 217
30 GraphicsServices 0x01e3e289 GSEventRun + 115
31 UIKit 0x003eec93 UIApplicationMain + 1160
32 Ace Metrix iPad 0x00002814 main + 102
33 Ace Metrix iPad 0x000027a5 start + 53
)
terminate called after throwing an instance of 'NSException'
You are calling removeObject: on an immutable instance of NSSet. Make sure that the set you work with is an instance of NSMutableSet. It might help us if you could post the code where you actually perform the deletes.
I got very weird issue with managedObjectContext:save. It hasn't happened at the first time I save the context, it only happens at some point of my program. Could you help me to know why it happened and where should I should find a bug in my code? Thanks.
Here is the log:
-[NSCFNumber UTF8String]: unrecognized selector sent to instance 0x5a64110
2011-05-19 16:02:43.235 DMC to Go[98212:40b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSCFNumber UTF8String]: unrecognized selector sent to instance 0x5a64110'
*** Call stack at first throw:
(
0 CoreFoundation 0x015d85a9 __exceptionPreprocess + 185
1 libobjc.A.dylib 0x0172c313 objc_exception_throw + 44
2 CoreFoundation 0x015da0bb -[NSObject(NSObject) doesNotRecognizeSelector:] + 187
3 CoreFoundation 0x01549966 ___forwarding___ + 966
4 CoreFoundation 0x01549522 _CF_forwarding_prep_0 + 50
5 CoreData 0x002f870f -[NSSQLiteConnection execute] + 1231
6 CoreData 0x0034aebd -[NSSQLiteConnection updateRow:] + 365
7 CoreData 0x00349e64 -[NSSQLConnection performAdapterOperations:] + 180
8 CoreData 0x00349b0e -[NSSQLCore _performChangesWithAdapterOps:] + 494
9 CoreData 0x003485ea -[NSSQLCore performChanges] + 410
10 CoreData 0x00342038 -[NSSQLCore saveChanges:] + 216
11 CoreData 0x00300199 -[NSSQLCore executeRequest:withContext:error:] + 409
12 CoreData 0x003b070b -[NSPersistentStoreCoordinator executeRequest:withContext:error:] + 3691
13 CoreData 0x00338948 -[NSManagedObjectContext save:] + 712
14 DMC to Go 0x0000313b -[dmcIpadAppDelegate saveManagedObjectChanges] + 107
15 DMC to Go 0x00020dc5 +[DmcIpadAppDelegate saveManagedObjectChanges] + 117
16 DMC to Go 0x00027883 -[DownloadFileService observeValueForKeyPath:ofObject:change:context:] + 867
17 Foundation 0x00fae1e4 NSKeyValueNotifyObserver + 361
18 Foundation 0x00fadca6 NSKeyValueDidChange + 384
19 Foundation 0x00f943e2 -[NSObject(NSKeyValueObserverNotification) didChangeValueForKey:] + 123
20 DMC to Go 0x0002c674 -[DownloadManager connectionDidFinishLoading:] + 836
21 Foundation 0x00fd4112 -[NSURLConnection(NSURLConnectionReallyInternal) sendDidFinishLoading] + 108
22 Foundation 0x00fd406b _NSURLConnectionDidFinishLoading + 133
23 CFNetwork 0x01dd948e _ZN19URLConnectionClient23_clientDidFinishLoadingEPNS_26ClientConnectionEventQueueE + 220
24 CFNetwork 0x01ea46e1 _ZN19URLConnectionClient26ClientConnectionEventQueue33processAllEventsAndConsumePayloadEP20XConnectionEventInfoI12XClientEvent18XClientEventParamsEl + 293
25 CFNetwork 0x01dcfc80 _ZN19URLConnectionClient13processEventsEv + 100
26 CFNetwork 0x01dcfacf _ZN17MultiplexerSource7performEv + 251
27 CoreFoundation 0x015b98ff __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 15
28 CoreFoundation 0x0151788b __CFRunLoopDoSources0 + 571
29 CoreFoundation 0x01516d86 __CFRunLoopRun + 470
30 CoreFoundation 0x01516840 CFRunLoopRunSpecific + 208
31 CoreFoundation 0x01516761 CFRunLoopRunInMode + 97
32 GraphicsServices 0x0202a1c4 GSEventRunModal + 217
33 GraphicsServices 0x0202a289 GSEventRun + 115
34 UIKit 0x00838c93 UIApplicationMain + 1160
35 DMC to Go 0x00001f59 main + 121
36 DMC to Go 0x00001ed5 start + 53
37 ??? 0x00000001 0x0 + 1
)
terminate called after throwing an instance of 'NSException'
Current language: auto; currently objective-c
Make sure you have no warnings
Put breakpoints in your code where you think you are setting an NSString on your object
And/Or NSLog %# the class of NSString properties of your core data objects and make sure it is some variation of an NSString. (NSLog(#"%#", [obj.property class]);)
What is happening is something that you are saving has an NSNumber object in place of an NSString. Since NSNumber does not respond to UTF8String your application is crashing.