I'm trying to create an iOS app which has a collectionview that takes information from a website (with JSON) and stores the info on CoreData.
I have 2 entities on CoreData.
1 Called Regions (wich will be the collection header texts).
1 Called Distributors (which will be the collection cells).
To use CollectionView + CoreData i have seen this example: https://github.com/AshFurrow/UICollectionViewExample
I set up everthing and works but sometimes, when i rotate the devide multiple times and the collection view still scrolls i see this error:
*** Terminating app due to uncaught exception 'NSRangeException', reason: 'NSMutableRLEArray objectAtIndex:effectiveRange:: Out of bounds'
*** First throw call stack:
(
0 CoreFoundation 0x01a9f5e4 __exceptionPreprocess + 180
1 libobjc.A.dylib 0x015738b6 objc_exception_throw + 44
2 CoreFoundation 0x01a9f3bb +[NSException raise:format:] + 139
3 Foundation 0x011a5f62 -[NSRLEArray objectAtIndex:effectiveRange:] + 131
4 Foundation 0x011a7b86 -[NSConcreteMutableAttributedString addAttribute:value:range:] + 212
5 UIFoundation 0x034aab82 __50-[NSConcreteTextStorage addAttribute:value:range:]_block_invoke + 156
6 UIFoundation 0x034aaa65 -[NSConcreteTextStorage addAttribute:value:range:] + 127
7 DataDetectorsUI 0x0a7da85c -[DDTextKitOperation _addResultsToAttributes] + 374
8 DataDetectorsUI 0x0a7daa82 __46-[DDTextKitOperation doURLificationOnDocument]_block_invoke_2 + 39
9 UIFoundation 0x034a9190 -[NSTextStorage(ActorSupport) coordinateAccess:] + 48
10 DataDetectorsUI 0x0a7daa54 __46-[DDTextKitOperation doURLificationOnDocument]_block_invoke + 134
11 libdispatch.dylib 0x0222d440 _dispatch_barrier_sync_f_slow_invoke + 71
12 libdispatch.dylib 0x0223e4b0 _dispatch_client_callout + 14
13 libdispatch.dylib 0x0222c75e _dispatch_main_queue_callback_4CF + 340
14 CoreFoundation 0x01b04a5e __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 14
15 CoreFoundation 0x01a456bb __CFRunLoopRun + 1963
16 CoreFoundation 0x01a44ac3 CFRunLoopRunSpecific + 467
17 CoreFoundation 0x01a448db CFRunLoopRunInMode + 123
18 GraphicsServices 0x03d569e2 GSEventRunModal + 192
19 GraphicsServices 0x03d56809 GSEventRun + 104
20 UIKit 0x002e1d3b UIApplicationMain + 1225
21 CollectionTest 0x0000934d main + 141
22 libdyld.dylib 0x024ce725 start + 0
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
I have created a demo app with everthing ready to launch it and check the error, you can download it here: https://www.dropbox.com/s/cg86896ld6240r5/CollectionTest.zip
I would appreciate any help if anyone know what could be the problem.
Thanks in advance.
I don't think this has anything to do with CoreData. I think this has to do with a bug in iOS 7 related to doURLificationOnDocument. We're running into this same problem in our app that makes no use of core data whatsoever. If you look at this stack overflow link: iOS 7 UITextView link detection crash in UITableView, you'll see that someone else is complaining about the same problem.
You are not using Core Data properly. Your entities have no relationships to each other. Instead, you are relying on some kind of foreign key. This is not appropriate for object graphs such as Core Data and can lead to all kinds of unpredictable errors, including the one you are encountering.
Read up on how Core Data models work. Pay particular attention to the chapter Relationships and Fetched Properties in the Core Data Programming Guide.
Related
In my app, I am displaying a map with annotations, and the user can browse the list of annotations in a table view (in a modal view controller).
I am experiencing a weird bug that I can reproduce both on device and in the simulator (iOS 7 & 8).
When in pitched mode, if I try to select an item in my POI table view, it does one of these :
changes the map center to a random point on the map, not the selected annotation.
crashes with the message that I put under (NSZombies enabled).
-[__NSCFString isPitched]: unrecognized selector sent to instance 0x7f24e6e0
I tried several methods to solve this bug, but with no success. And what puzzles me is I can't find any information on the isPitched method. It isn't in my code, neither in Apple documentation.
Does someone knows more on MapKit and these types of problem ?
Alternatively, would you know a way to deactivate the pitch when a user select a POI in the list ? Maybe it would prevent the bug.
EDIT : Just found that the 'isPitched' method is actually part of VectorKit ! Doesn't really help, though. No documentation on VectorKit...
EDIT 2 : Added stack trace.
-[__NSCFString isPitched]: unrecognized selector sent to instance 0x7db84870
2015-02-28 14:25:08.501 Cartel 2015[2481:178443] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFString isPitched]: unrecognized selector sent to instance 0x7db84870'
*** First throw call stack:
(
0 CoreFoundation 0x00afb946 __exceptionPreprocess + 182
1 libobjc.A.dylib 0x00784a97 objc_exception_throw + 44
2 CoreFoundation 0x00b035c5 -[NSObject(NSObject) doesNotRecognizeSelector:] + 277
3 CoreFoundation 0x00a4c3e7 ___forwarding___ + 1047
4 CoreFoundation 0x00a4bfae _CF_forwarding_prep_0 + 14
5 VectorKit 0x02dd09c1 __86-[VKMapCameraController _animateToPosition:pitch:yaw:duration:timingCurve:completion:]_block_invoke + 1809
6 VectorKit 0x02d88645 -[VKAnimation onTimerFired:] + 357
7 VectorKit 0x02d9895e -[VKScreenCanvas animateWithTimestamp:] + 686
8 VectorKit 0x02d9850e -[VKScreenCanvas updateWithTimestamp:] + 46
9 VectorKit 0x02d71e69 -[VKMapView onTimerFired:] + 89
10 libobjc.A.dylib 0x0079a771 -[NSObject performSelector:withObject:] + 70
11 VectorKit 0x0323463c -[GGLDisplayLink _displayLinkFired:] + 60
12 QuartzCore 0x041abcad _ZN2CA7Display15DisplayLinkItem8dispatchEv + 45
13 QuartzCore 0x041abb83 _ZN2CA7Display11DisplayLink14dispatch_itemsEyyy + 311
14 QuartzCore 0x041ac067 _ZN2CA7Display16TimerDisplayLink8callbackEP16__CFRunLoopTimerPv + 123
15 CoreFoundation 0x00a558d6 __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 22
16 CoreFoundation 0x00a5525d __CFRunLoopDoTimer + 1309
17 CoreFoundation 0x00a146ba __CFRunLoopRun + 2090
18 CoreFoundation 0x00a13bcb CFRunLoopRunSpecific + 443
19 CoreFoundation 0x00a139fb CFRunLoopRunInMode + 123
20 GraphicsServices 0x03f4324f GSEventRunModal + 192
21 GraphicsServices 0x03f4308c GSEventRun + 104
22 UIKit 0x00f318b6 UIApplicationMain + 1526
23 Cartel 2015 0x0001110d main + 141
24 libdyld.dylib 0x046aaac9 start + 1
25 ??? 0x00000001 0x0 + 1
OK, I managed to prevent the crash with the following fix.
When a POI is selected in my list, I trigger a delegate method of the view controller that handles the MapView from the didSelect method of the controller of the tableView. If you have the same problem, I assume you understand what I mean, so far.
In this method, I asked the MapView to center itself on the coordinates of the POI.
Now, to solve the problem that only happened when the user tracking mode was set to "pitched" (following your orientation), I simply added a line to deactivate this tracking mode at the beginning of my method :
[mapView setUserTrackingMode: MKUserTrackingModeNone] ;
This removed the crashes that randomly appeared. Notice that it doesn't result in a counterintuitive behavior because this tracking mode is automatically deactivated when the user moves the map.
So problem solved for me but if you have any information about this isPitched selector and what really caused the problem, you're very welcome to post it here !
I have a problem with the CoreData and fulfilling managedObjects.
Stack trace:
Uncaught exception: CoreData could not fulfill a fault for '0x11cec410 <x-coredata://08BF0B39-BA5D-404E-B75E-FD4FA906DE3E/TaskDescription/p1747>'. Stack trace: (
"4 libc++abi.dylib 0x03553f60 _ZSt11__terminatePFvvE + 14",
"5 libc++abi.dylib 0x03553b97 __cxa_rethrow + 103",
"6 libobjc.A.dylib 0x02cb0a57 objc_exception_rethrow + 47",
"7 CoreFoundation 0x02f95bc5 CFRunLoopRunSpecific + 613",
"8 CoreFoundation 0x02f9594b CFRunLoopRunInMode + 123"
)
*** Terminating app due to uncaught exception 'NSObjectInaccessibleException', reason: 'CoreData could not fulfill a fault for '0x11cec410 <x-coredata://08BF0B39-BA5D-404E-B75E-FD4FA906DE3E/TaskDescription/p1747>''
*** First throw call stack:
(
0 CoreFoundation 0x02ff05e4 __exceptionPreprocess + 180
1 libobjc.A.dylib 0x02cb08b6 objc_exception_throw + 44
2 CoreData 0x0298666b _PFFaultHandlerLookupRow + 2715
3 CoreData 0x02985bc7 -[NSFaultHandler fulfillFault:withContext:forIndex:] + 39
4 CoreData 0x029857a3 _PF_FulfillDeferredFault + 259
5 CoreData 0x029855f6 _sharedIMPL_pvfk_core + 70
6 CoreData 0x0298a005 -[NSManagedObject(_PFDynamicAccessorsAndPropertySupport) _genericValueForKey:withIndex:flags:] + 85
7 CoreData 0x029c3ab1 _PF_Handler_Public_GetProperty + 161
8 CoreData 0x029c39b5 -[NSManagedObject valueForKey:] + 149
9 Foundation 0x0254e065 -[NSFunctionExpression expressionValueWithObject:context:] + 1260
10 Foundation 0x025d4109 -[NSComparisonPredicate evaluateWithObject:substitutionVariables:] + 248
11 Foundation 0x025d4009 -[NSPredicate evaluateWithObject:] + 48
12 CoreData 0x02a8f991 -[NSFetchedResultsController(PrivateMethods) _objectInResults:] + 113
13 CoreData 0x02a912c2 -[NSFetchedResultsController(PrivateMethods) _preprocessUpdatedObjects:insertsInfo:deletesInfo:updatesInfo:sectionsWithDeletes:newSectionNames:treatAsRefreshes:] + 642
14 CoreData 0x02a926f4 -[NSFetchedResultsController(PrivateMethods) _managedObjectContextDidChange:] + 1892
15 Foundation 0x02622e39 __57-[NSNotificationCenter addObserver:selector:name:object:]_block_invoke + 40
16 CoreFoundation 0x0304c524 __CFNOTIFICATIONCENTER_IS_CALLING_OUT_TO_AN_OBSERVER__ + 20
17 CoreFoundation 0x02fa407b _CFXNotificationPost + 2859
18 Foundation 0x0255cb91 -[NSNotificationCenter postNotificationName:object:userInfo:] + 98
19 CoreData 0x029974a3 -[NSManagedObjectContext(_NSInternalNotificationHandling) _postObjectsDidChangeNotificationWithUserInfo:] + 83
20 CoreData 0x02a36abf -[NSManagedObjectContext(_NSInternalChangeProcessing) _createAndPostChangeNotification:withDeletions:withUpdates:withRefreshes:] + 367
21 CoreData 0x02993168 -[NSManagedObjectContext(_NSInternalChangeProcessing) _postRefreshedObjectsNotificationAndClearList] + 136
22 CoreData 0x02992d14 -[NSManagedObjectContext(_NSInternalChangeProcessing) _processRecentChanges:] + 3140
23 CoreData 0x029920c9 -[NSManagedObjectContext processPendingChanges] + 41
24 CoreData 0x02966311 _performRunLoopAction + 321
25 CoreFoundation 0x02fb853e __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 30
26 CoreFoundation 0x02fb848f __CFRunLoopDoObservers + 399
27 CoreFoundation 0x02f963b4 __CFRunLoopRun + 1076
28 CoreFoundation 0x02f95b33 CFRunLoopRunSpecific + 467
29 CoreFoundation 0x02f9594b CFRunLoopRunInMode + 123
30 GraphicsServices 0x0488d9d7 GSEventRunModal + 192
31 GraphicsServices 0x0488d7fe GSEventRun + 104
32 UIKit 0x016c294b UIApplicationMain + 1225
33 MYAPP 0x0003bb9d main + 141
34 MYAPP 0x00003055 start + 53
)
libc++abi.dylib: terminating with uncaught exception of type _NSCoreDataException
All I can see when app crashes is that trace with only showing some internal CoreData/Foundation instructions. Can anyone please explain me, what is going on with that
NSFetchedResultsController(PrivateMethods)
or
NSManagedObjectContext(_NSInternalChangeProcessing)
It looks very weird to me. How can I prevent from such NSObjectInaccessibleException?
I know that this error is due to previously deleted object. I have many background contexts run asynchronously, but I think that I am keeping the rules given by Apple documentation about concurrency with CoreData. It crashes only sometimes and I can't see anything from this point. Anyone had similar situation?
This has nothing to do with the methods you mentioned.
Nor can you avoid this issue in a multi-context environment where you have more then one child context with the same parent (nil parent included).
This might happen in a multi-context environment (or some unique cases) where one context hold a fault for some object (which he consider to exist) but in the mean time another context delete the object from the store and not notifying the other context of the deletion (before the context holding the fault attempt to fulfil it.
Using a FRC in a multi-context environment ,which does not use a parent child architecture where the FRC context is the parent for all child contexts will always be vulnerable to this exception.
See HERE for some more usecases.
A possible solution would be to delay your actual deletion of FRC tracked objects:
first mark them for deletion (your FRC predicate should take this new property into account)
Then use a background operation to delete objects that were marked for deletion (every given time interval)
A partial solution would be to use a parent child context architecture funnelling all events through the context the FRC is observing.
This is a partial solution due to the fact that this move the problem one level up to the child contexts that are unaware of each other deletions (if child contexts never deal with the same objects in parallel then you might avoid this issue).
I've been struggling with Core Data for 3 days now and I'm only going backwards. I had to restore my entire project from a backup and now I get this:
2014-01-06 14:47:45.911 MyClub[1980:5003] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Can't merge models with two different entities named 'SuperGroups''
*** First throw call stack:
(
0 CoreFoundation 0x0000000101e70795 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x0000000101bd3991 objc_exception_throw + 43
2 CoreData 0x00000001000fba1d +[NSManagedObjectModel modelByMergingModels:] + 3357
3 CoreData 0x00000001000b8e49 +[NSManagedObjectModel mergedModelFromBundles:] + 521
4 MyClub 0x0000000100008499 -[AppDelegate managedObjectModel] + 105
5 MyClub 0x00000001000085fa -[AppDelegate persistentStoreCoordinator] + 266
6 MyClub 0x000000010000836c -[AppDelegate managedObjectContext] + 92
7 MyClub 0x000000010000b112 __38-[MyDownloader populateSuperGroupList]_block_invoke + 1058
8 CFNetwork 0x000000010273240e __50-[__NSCFLocalDownloadTask _private_fileCompletion]_block_invoke227 + 83
9 Foundation 0x00000001017fc19b -[NSBlockOperation main] + 75
10 Foundation 0x000000010184a844 -[__NSOperationInternal _start:] + 623
11 Foundation 0x000000010184c71b __NSOQSchedule_f + 64
12 libdispatch.dylib 0x0000000102d4e6fd _dispatch_client_callout + 8
13 libdispatch.dylib 0x0000000102d3de37 _dispatch_queue_drain + 481
14 libdispatch.dylib 0x0000000102d3dbfc _dispatch_queue_invoke + 112
15 libdispatch.dylib 0x0000000102d3eb14 _dispatch_root_queue_drain + 257
16 libdispatch.dylib 0x0000000102d3ed65 _dispatch_worker_thread2 + 40
17 libsystem_pthread.dylib 0x00000001030f8ef8 _pthread_wqthread + 314
18 libsystem_pthread.dylib 0x00000001030fbfb9 start_wqthread + 13
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
What do I do (other than swear loudly and profusely at Core Data, which I've already tried multiple times)?
It appears you have two managed object models in your project (Both have an entity in them named SuperGroups). Try loading a specific one via its URL, or deleting the duplicate from your project.
Whenever you make a change to the Core Data's Object Model you have to make sure you get rid of the application on your simulator/phone. The model on the device must match the model in your code or you will get an error.
There is a process in place that will allow you to technically have two seperate models so that when you say put an update in to the app store you can do it without users having to delete all their data. If you ever need this I would look into "Core Data Versioning".
I am developing an application which uses CoreData. The view contains a UITableView (containing around 50 elements) which uses a NSFetchedResultsController. There is also a "Pull to refresh" which permits to refresh the stored data after a WS call (in another thread with a new managed object context).
Everything is working fine on iOS5: the database and the tableview are refreshed when I perform a "Pull to refresh". However there is a problem with iOS4. The first "performFetch" works when the application is launched (the tableview contains all database records) but I've got the following error when I perform a "Pull to refresh":
2012-02-29 11:56:09.119 Nanopost[1996:207] *** Terminating app due to uncaught exception 'NSObjectInaccessibleException', reason: 'CoreData could not fulfill a fault for '0x5c3c760 <x-coredata://E176B0A1-275B-4332-9231-49FD88238C2B/Ads/p231>''
*** Call stack at first throw:
(
0 CoreFoundation 0x02bfe919 __exceptionPreprocess + 185
1 libobjc.A.dylib 0x02e595de objc_exception_throw + 47
2 CoreData 0x028b833f _PFFaultHandlerLookupRow + 1407
3 CoreData 0x028b5ee3 _PF_FulfillDeferredFault + 499
4 CoreData 0x028b9f3f _sharedIMPL_pvfk_core + 95
5 CoreData 0x0292a010 _PF_Handler_Public_GetProperty + 160
6 Foundation 0x02442c4f -[NSSortDescriptor compareObject:toObject:] + 128
7 CoreData 0x0297db5e +[NSFetchedResultsController(PrivateMethods) _insertIndexForObject:inArray:lowIdx:highIdx:sortDescriptors:] + 286
8 CoreData 0x0297e1b2 -[NSFetchedResultsController(PrivateMethods) _postprocessInsertedObjects:] + 402
9 CoreData 0x029841bc -[NSFetchedResultsController(PrivateMethods) _managedObjectContextDidChange:] + 1804
10 Foundation 0x02380c1d _nsnote_callback + 145
11 CoreFoundation 0x02bd6cf9 __CFXNotificationPost_old + 745
12 CoreFoundation 0x02b5611a _CFXNotificationPostNotification + 186
13 Foundation 0x023767c2 -[NSNotificationCenter postNotificationName:object:userInfo:] + 134
14 CoreData 0x028c0519 -[NSManagedObjectContext(_NSInternalNotificationHandling) _postObjectsDidChangeNotificationWithUserInfo:] + 89
15 CoreData 0x028f802b -[NSManagedObjectContext mergeChangesFromContextDidSaveNotification:] + 1579
16 Foundation 0x02395e9a __NSThreadPerformPerform + 251
17 CoreFoundation 0x02bdfd7f __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 15
18 CoreFoundation 0x02b3e2cb __CFRunLoopDoSources0 + 571
19 CoreFoundation 0x02b3d7c6 __CFRunLoopRun + 470
20 CoreFoundation 0x02b3d280 CFRunLoopRunSpecific + 208
21 CoreFoundation 0x02b3d1a1 CFRunLoopRunInMode + 97
22 GraphicsServices 0x031e62c8 GSEventRunModal + 217
23 GraphicsServices 0x031e638d GSEventRun + 115
24 UIKit 0x0063cb58 UIApplicationMain + 1160
25 Nanopost 0x0000230a main + 170
26 Nanopost 0x00002255 start + 53
)
terminate called after throwing an instance of '_NSCoreDataException'
When I initialize the "NSFetchRequest", I set the "FetchBatchSize" to 20 (randomly):
[l_FetchRequest setFetchBatchSize:20];
But if I set the "FetchBatchSize" to 25:
[l_FetchRequest setFetchBatchSize:25];
... No more crashes on iOS4 and I don't know why and I want to understand this issue :) I don't think that this line is the real problem. Maybe it indicates another problem somewhere?
Thank you very much in advance for your answers!
Thomas
Is there a reason you are using a different context? I don't switch mine, and I have a pretty similar sounding app.
One thing you might compare to is this very handy CoreDataTableViewController:
http://www.stanford.edu/class/cs193p/cgi-bin/drupal/node/289
I use it and haven't had any issues (though I am not running in iOS 4). You might compare how you hooked up the fetchedResultsController.
One other point - do you have the catch-all breakpoint to push the debugger as soon as an exception is raised? If not, add it (breakpoints, + to add, "Add Exception Breakpoint" and keep defaults). That will put you into the debugger right on the line that raises the exception, which should be useful.
Good luck,
Damien
I'm new here but I've been reading along a lot. Mostely I found what I was looking for but now I'm stuck. Reading documentation and asking google didn't help so here I go:
I have an app that adds events to the user's calendar using EKEventstore. I used to do this all from one single view controller, including the function to pick one of the user's calendars. I've been creating eventstores several times in the code, and everything worked fine.
Now I've upgraded my app to some more professional coding, including several view controllers. One is handling the calendar picker (simple table view listing all calendars), another one does the creation and saving of new events to the calendar.
The EKEvenstore is declared in the appdelegate.h
EKEventStore *es;
Each view controller defines the evenststore in it's viewWillAppear method:
es=[[EKEventStore alloc]init];
Everything works fine, I can load and safe events from and to the eventstore, but as soon as I switch to the calendar picker view controller (just loading it up), and then going back to the view controller that creates events, the app crashes. After a new launch I everything is fine again. Any Idea is highly appreciated.
Here's my stack after the exception throw:
2011-08-25 15:35:18.795 Dutysheet Wx[13864:707] -[UINavigationButton refresh]: unrecognized selector sent to instance 0x688f0a0
2011-08-25 15:35:18.822 Dutysheet Wx[13864:707] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UINavigationButton refresh]: unrecognized selector sent to instance 0x688f0a0'
* Call stack at first throw:
(
0 CoreFoundation 0x30b1364f exceptionPreprocess + 114
1 libobjc.A.dylib 0x3462ec5d objc_exception_throw + 24
2 CoreFoundation 0x30b171bf -[NSObject(NSObject) doesNotRecognizeSelector:] + 102
3 CoreFoundation 0x30b16649 __forwarding + 508
4 CoreFoundation 0x30a8d180 _CF_forwarding_prep_0 + 48
5 EventKit 0x339bfe1b -[EKEventStore _databaseChangedExternally] + 682
6 EventKit 0x339bf49f DatabaseChanged + 18
7 CoreFoundation 0x30ae2d69 CFNotificationCenterDarwinCallBack + 24
8 CoreFoundation 0x30adfbdf __CFMachPortPerform + 210
9 CoreFoundation 0x30aeaa97 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION + 26
10 CoreFoundation 0x30aec83f __CFRunLoopDoSource1 + 166
11 CoreFoundation 0x30aed60d __CFRunLoopRun + 520
12 CoreFoundation 0x30a7dec3 CFRunLoopRunSpecific + 230
13 CoreFoundation 0x30a7ddcb CFRunLoopRunInMode + 58
14 GraphicsServices 0x303fc41f GSEventRunModal + 114
15 GraphicsServices 0x303fc4cb GSEventRun + 62
16 UIKit 0x30ba3d69 -[UIApplication _run] + 404
17 UIKit 0x30ba1807 UIApplicationMain + 670
18 Dutysheet Wx 0x00002a83 main + 82
19 Dutysheet Wx 0x000029f8 start + 52
)
terminate called after throwing an instance of 'NSException'