iOS 5: NSDictionary encodeWithCoder inserts nil into array - ios

I am seeing a problem that seems to be unique to iOS 5, where trying to encode a dictionary results in a crash because an array is populated with a nil object in the process.
This is confusing to me because I would think in order for the following to happen, the dictionary would need to contain nil, which I would expect would crash at the time the dictionary is populated as opposed to when it is encoded.
Any idea what could be causing this?
Application Specific Information:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSPlaceholderArray initWithObjects:count:]: attempt to insert nil object from objects[0]'
Last Exception Backtrace:
0 CoreFoundation 0x3277088f ___exceptionPreprocess + 163
1 libobjc.A.dylib 0x347c6259 _objc_exception_throw + 33
2 CoreFoundation 0x326c29e9 -[__NSPlaceholderArray initWithObjects:count:] + 129
3 Foundation 0x38071be7 -[NSDictionary(NSDictionary) encodeWithCoder:] + 819
4 Foundation 0x38047aa1 __encodeObject + 961
5 Tumblr 0x00105bab -[MyModelObject encodeWithCoder:] (MyModelObject.m:474)
6 Foundation 0x38047aa1 __encodeObject + 961
7 Foundation 0x380473c9 +[NSKeyedArchiver archivedDataWithRootObject:] + 161
8 CoreData 0x31e6cca7 -[NSSQLiteConnection execute] + 2219
9 CoreData 0x31f3455f -[NSSQLiteConnection updateRow:] + 551
10 CoreData 0x31f1120d -[NSSQLConnection performAdapterOperation:] + 85
11 CoreData 0x31f11183 -[NSSQLConnection performAdapterOperations:] + 115
12 CoreData 0x31f1c38b -[NSSQLCore _performChangesWithAdapterOps:] + 207
13 CoreData 0x31f1bfcb -[NSSQLCore performChanges] + 623
14 CoreData 0x31f1afc5 -[NSSQLCore saveChanges:] + 309
15 CoreData 0x31e7325f -[NSSQLCore executeRequest:withContext:error:] + 947
16 CoreData 0x31e72337 -[NSPersistentStoreCoordinator executeRequest:withContext:error:] + 1131
17 CoreData 0x31eda287 -[NSManagedObjectContext save:] + 523

Related

How to format a core data many to many predicate with an intermediate model

I have the following core data model:
I have a view controller that contains a particular SkillGroup. I would like to make a fetch request that contains the records for all skills in that skillGroup. Normally I would think it would be something like
request.predicate = NSPredicate(format: "skill IN %#.skills", skillGroup!)
However I needed to create the intermediate "SkillGroupItem" models so that I could keep track of the displayIndex for each skill in a skillGroup. I am thinking of something like:
request.predicate = NSPredicate(format: "ANY %#.skillGroupItems.skill = skillProgress.skill", skillGroup!)
so any of the skillGroup's skillGroupItems' skill is equal to the records skillProgress object.skill...
but that throws this error:
CoreData: annotation: to-many relationship fault "skillGroupItems" for objectID 0xb9291ca50355a7c1 <x-coredata://33325602-3973-46E7-8400-45922DD97A05/SkillGroup/p1> fulfilled from database. Got 1 rows
CoreData: sql: SELECT DISTINCT t0.Z_ENT, t0.Z_PK, t0.Z_OPT, t0.ZRECORDTYPE, t0.ZTIMESTAMP, t0.ZSKILLPROGRESS, t0.ZIMAGEFILENAME, t0.ZTEXT, t0.ZTHUMBNAILFILENAME, t0.ZVIDEOFILENAME FROM ZRECORD t0 JOIN ZSKILLPROGRESS t1 ON t0.ZSKILLPROGRESS = t1.Z_PK WHERE ? = t1.ZSKILL ORDER BY t0.ZTIMESTAMP
2021-04-20 13:37:43.482875-0700 SweatNetOffline[38167:3014868] -[__NSSingleObjectSetI longLongValue]: unrecognized selector sent to instance 0x600002a69360
CoreData: annotation: total fetch execution time: 0.0013s for 0 rows.
2021-04-20 13:37:43.484519-0700 SweatNetOffline[38167:3014868] [error] error: SQLCore dispatchRequest: exception handling request: <NSSQLFetchRequestContext: 0x60000117d5e0> , -[__NSSingleObjectSetI longLongValue]: unrecognized selector sent to instance 0x600002a69360 with userInfo of (null)
CoreData: error: SQLCore dispatchRequest: exception handling request: <NSSQLFetchRequestContext: 0x60000117d5e0> , -[__NSSingleObjectSetI longLongValue]: unrecognized selector sent to instance 0x600002a69360 with userInfo of (null)
2021-04-20 13:37:43.503515-0700 SweatNetOffline[38167:3014868] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSSingleObjectSetI longLongValue]: unrecognized selector sent to instance 0x600002a69360'
*** First throw call stack:
(
0 CoreFoundation 0x00007fff20421af6 __exceptionPreprocess + 242
1 libobjc.A.dylib 0x00007fff20177e78 objc_exception_throw + 48
2 CoreFoundation 0x00007fff204306f7 +[NSObject(NSObject) instanceMethodSignatureForSelector:] + 0
3 CoreFoundation 0x00007fff20426036 ___forwarding___ + 1489
4 CoreFoundation 0x00007fff20428068 _CF_forwarding_prep_0 + 120
5 CoreData 0x00007fff25114346 -[NSSQLiteConnection execute] + 1416
6 CoreData 0x00007fff2538acfa _newFetchedRowsForFetchPlan_ST + 1234
7 CoreData 0x00007fff2537b1c5 _executeFetchRequest + 55
8 CoreData 0x00007fff252cd352 -[NSSQLFetchRequestContext executeRequestCore:] + 41
9 CoreData 0x00007fff253430a3 -[NSSQLStoreRequestContext executeRequestUsingConnection:] + 405
10 CoreData 0x00007fff2531468f __52-[NSSQLDefaultConnectionManager handleStoreRequest:]_block_invoke + 56
11 CoreData 0x00007fff2527bdbd __37-[NSSQLiteConnection performAndWait:]_block_invoke + 28
12 libdispatch.dylib 0x00000001094479c8 _dispatch_client_callout + 8
13 libdispatch.dylib 0x0000000109456bfe _dispatch_lane_barrier_sync_invoke_and_complete + 132
14 CoreData 0x00007fff2527bca3 -[NSSQLiteConnection performAndWait:] + 134
15 CoreData 0x00007fff253145a4 -[NSSQLDefaultConnectionManager handleStoreRequest:] + 273
16 CoreData 0x00007fff2531afd8 -[NSSQLCoreDispatchManager routeStoreRequest:] + 283
17 CoreData 0x00007fff2524b284 -[NSSQLCore dispatchRequest:withRetries:] + 161
18 CoreData 0x00007fff2524681e -[NSSQLCore processFetchRequest:inContext:] + 88
19 CoreData 0x00007fff2511a461 -[NSSQLCore executeRequest:withContext:error:] + 1072
20 CoreData 0x00007fff2522595a __65-[NSPersistentStoreCoordinator executeRequest:withContext:error:]_block_invoke.797 + 3219
21 CoreData 0x00007fff2521e02a -[NSPersistentStoreCoordinator _routeHeavyweightBlock:] + 222
22 CoreData 0x00007fff2511993e -[NSPersistentStoreCoordinator executeRequest:withContext:error:] + 1684
23 CoreData 0x00007fff25117ef2 -[NSManagedObjectContext executeFetchRequest:error:] + 885
24 CoreData 0x00007fff252da7d0 __43-[NSFetchedResultsController performFetch:]_block_invoke + 417
25 CoreData 0x00007fff2514ce63 developerSubmittedBlockToNSManagedObjectContextPerform + 154
26 CoreData 0x00007fff2514cd4a -[NSManagedObjectContext performBlockAndWait:] + 197
27 CoreData 0x00007fff252dcc13 -[NSFetchedResultsController _recursivePerformBlockAndWait:withContext:] + 145
28 CoreData 0x00007fff252da523 -[NSFetchedResultsController performFetch:] + 231
29 SweatNetOffline 0x0000000108ece722 $s15SweatNetOffline22ProgressViewControllerC11viewDidLoadyyF + 1122
30 SweatNetOffline 0x0000000108ecf8db $s15SweatNetOffline22ProgressViewControllerC11viewDidLoadyyFTo + 43
31 UIKitCore 0x00007fff23f5e36e -[UIViewController _sendViewDidLoadWithAppearanceProxyObjectTaggingEnabled] + 88
32 UIKitCore 0x00007fff23f62cd7 -[UIViewController loadViewIfRequired] + 1084
33 UIKitCore 0x00007fff23f630c1 -[UIViewController view] + 27
34 UIKitCore 0x00007fff23e82c37 -[UINavigationController _startCustomTransition:] + 1254
35 UIKitCore 0x00007fff23e991d6 -[UINavigationController _startDeferredTransitionIfNeeded:] + 684
36 UIKitCore 0x00007fff23e9a5e8 -[UINavigationController __viewWillLayoutSubviews] + 150
37 UIKitCore 0x00007fff23e7ad9e -[UILayoutContainerView layoutSubviews] + 217
38 UIKitCore 0x00007fff24bf8504 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 2924
39 QuartzCore 0x00007fff27b1bc2b -[CALayer layoutSublayers] + 258
40 QuartzCore 0x00007fff27b2219d _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 575
41 QuartzCore 0x00007fff27b2df3f _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 65
42 QuartzCore 0x00007fff27a6d44c _ZN2CA7Context18commit_transactionEPNS_11TransactionEdPd + 496
43 QuartzCore 0x00007fff27aa4233 _ZN2CA11Transaction6commitEv + 783
44 QuartzCore 0x00007fff27aa53ef _ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv + 79
45 CoreFoundation 0x00007fff2038f1f8 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 23
46 CoreFoundation 0x00007fff20389a77 __CFRunLoopDoObservers + 547
47 CoreFoundation 0x00007fff2038a01a __CFRunLoopRun + 1113
48 CoreFoundation 0x00007fff203896d6 CFRunLoopRunSpecific + 567
49 GraphicsServices 0x00007fff2c257db3 GSEventRunModal + 139
50 UIKitCore 0x00007fff24696cf7 -[UIApplication _run] + 912
51 UIKitCore 0x00007fff2469bba8 UIApplicationMain + 101
52 SweatNetOffline 0x0000000108e3d9fb main + 75
53 libdyld.dylib 0x00007fff2025a3e9 start + 1
54 ??? 0x0000000000000003 0x0 + 3
)
libc++abi.dylib: terminating with uncaught exception of type NSException
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSSingleObjectSetI longLongValue]: unrecognized selector sent to instance 0x600002a69360'
terminating with uncaught exception of type NSException
CoreSimulator 732.18.6 - Device: iPhone 11 (E5E1A675-AA38-45CE-A047-1C5569598381) - Runtime: iOS 14.4 (18D46) - DeviceType: iPhone 11
Im tripped up by how to use the ANY in this case. so any of the skillGroupItems makes sense.. but ANY skillGroup.skillGroupItems.skill seems bad to me. You can't look for a .skill on an array of skillGroupItems.
Any advice on how to accomplish this? Thanks
The predicate is parsed using the entity you are fetching (in your case, Record) as the reference point. So you would use this:
request.predicate = NSPredicate(format: "recordType == %#", givenRecordType)
to create a predicate based on the attribute recordType, and
request.predicate = NSPredicate(format: "skillProgress == %#", givenSkillProgressObject)
to create a predicate based on the relationship skillProgress (if givenSkillProgress was a SkillProgress object you already had fetched). If you do not have a SkillProgress object in memory, but you know an attribute value you want to match for it, you can use the corresponding keypath expression to refer to the attribute of the related object, eg:
request.predicate = NSPredicate(format: "skillProgress.isActive == YES")
will fetch those Record objects whose related SkillProgress object is active. You can continue to "traverse" the relationship tree by using additional elements in the key path. So:
request.predicate = NSPredicate(format: "skillProgress.skill.id == %#", givenSkillID)
will fetch those Record objects whose related SkillProgress is in turn related to a Skill whose id attribute matches the givenSkillID. For the skillGroupItems relationship (on the Skill entity), because it is to-many, you will need to use "ANY" to indicate that any of the related objects should match your criteria:
request.predicate = NSPredicate(format: "ANY skillProgress.skill.skillGroupItems == %#", givenSkillGroupItem)
The final step is then to use the skillGroup relationship from SkillGroupItem to get the full key path from Record to SkillGroup:
request.predicate = NSPredicate(format: "ANY skillProgress.skill.skillGroupItems.skillGroup == %#", givenSkillGroup)

Crash Core Data only in iOS 14

I work on an app which use CoreData, everything works fine on iOS 13 and iOS 14 with differents Xcode betas. But since Apple released the official release for iOS 14 and Xcode 12 I have a crash when I try to get some objects from CoreData.
guard let customers = Customer.mr_findAllSorted(by: "login", ascending: true) as? [Customer] else { return }
Console output :
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Can't get value for 'batch' in bindings {
}.'
When I try to print the object from console log with breakpoint, I have a memory address of object but when I try to print some values of this object I have this error :
error: warning: couldn't get required object pointer (substituting NULL): Couldn't load 'self' because its value couldn't be evaluated
error: Execution was interrupted, reason: internal ObjC exception breakpoint(-5)..
The process has been returned to the state before expression evaluation.
Has anyone ever had to deal with this type of errors since the official versions ?
Thanks in advance for your help.
We're seeing this too in our app. It is only reproducible with iOS 14 and apparently the latest SDKs in Xcode 12.0.1, but we don't have any solutions or answers as to why this is occurring yet.
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Can't get value for 'batch' in bindings {
}.'
*** First throw call stack:
(
0 CoreFoundation 0x00007fff2043a126 __exceptionPreprocess + 242
1 libobjc.A.dylib 0x00007fff20177f78 objc_exception_throw + 48
2 Foundation 0x00007fff2088bedc -[NSVariableExpression _expressionWithSubstitutionVariables:] + 0
3 Foundation 0x00007fff2075ac7b -[NSComparisonPredicate evaluateWithObject:substitutionVariables:] + 264
4 CoreData 0x00007fff2511ec68 -[NSDictionaryStoreMap handleFetchRequest:] + 481
5 CoreData 0x00007fff2511dfd2 -[NSMappedObjectStore executeFetchRequest:withContext:] + 230
6 CoreData 0x00007fff251e10a2 __65-[NSPersistentStoreCoordinator executeRequest:withContext:error:]_block_invoke.797 + 3219
7 CoreData 0x00007fff251d988d __55-[NSPersistentStoreCoordinator _routeHeavyweightBlock:]_block_invoke + 55
8 CoreData 0x00007fff251edf0a gutsOfBlockToNSPersistentStoreCoordinatorPerform + 182
9 libdispatch.dylib 0x000000010a6b0a88 _dispatch_client_callout + 8
10 libdispatch.dylib 0x000000010a6bfcac _dispatch_lane_barrier_sync_invoke_and_complete + 132
11 CoreData 0x00007fff251d9492 _perform + 169
12 CoreData 0x00007fff251d9740 -[NSPersistentStoreCoordinator _routeHeavyweightBlock:] + 172
13 CoreData 0x00007fff250d640e -[NSPersistentStoreCoordinator executeRequest:withContext:error:] + 1684
14 CoreData 0x00007fff250d49c2 -[NSManagedObjectContext executeFetchRequest:error:] + 885
15 CoreData 0x00007fff251a9d7f -[NSManagedObjectContext _parentObjectsForFetchRequest:inContext:error:] + 477
16 CoreData 0x00007fff251aa774 __82-[NSManagedObjectContext(_NestedContextSupport) executeRequest:withContext:error:]_block_invoke + 603
17 CoreData 0x00007fff25109de8 internalBlockToNSManagedObjectContextPerform + 89
18 libdispatch.dylib 0x000000010a6b0a88 _dispatch_client_callout + 8
19 libdispatch.dylib 0x000000010a6bfcac _dispatch_lane_barrier_sync_invoke_and_complete + 132
20 CoreData 0x00007fff25109d6f _perform + 196
21 CoreData 0x00007fff25109b93 -[NSManagedObjectContext(_NestedContextSupport) executeRequest:withContext:error:] + 175
22 CoreData 0x00007fff250d49c2 -[NSManagedObjectContext executeFetchRequest:error:] + 885
23 CoreData 0x00007fff251a9d7f -[NSManagedObjectContext _parentObjectsForFetchRequest:inContext:error:] + 477
24 CoreData 0x00007fff251aa774 __82-[NSManagedObjectContext(_NestedContextSupport) executeRequest:withContext:error:]_block_invoke + 603
25 CoreData 0x00007fff25109de8 internalBlockToNSManagedObjectContextPerform + 89
26 libdispatch.dylib 0x000000010a6b0a88 _dispatch_client_callout + 8
27 libdispatch.dylib 0x000000010a6bfe11 _dispatch_async_and_wait_invoke + 175
28 libdispatch.dylib 0x000000010a6b0a88 _dispatch_client_callout + 8
29 libdispatch.dylib 0x000000010a6bef23 _dispatch_main_queue_callback_4CF + 1152
30 CoreFoundation 0x00007fff203a8276 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 9
31 CoreFoundation 0x00007fff203a2b06 __CFRunLoopRun + 2685
32 CoreFoundation 0x00007fff203a1b9e CFRunLoopRunSpecific + 567
33 GraphicsServices 0x00007fff2b773db3 GSEventRunModal + 139
34 UIKitCore 0x00007fff24660af3 -[UIApplication _run] + 912
35 UIKitCore 0x00007fff24665a04 UIApplicationMain + 101
36 XXXX 0x0000000106de2d69 main + 153
37 libdyld.dylib 0x00007fff20257415 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Can't get value for 'batch' in bindings {
}.'
You may set batch size to 0 [NSManagedObject MR_setDefaultBatchSize:0];, but check you performance after.

CoreData Error SIGABRT: keypath AttributeName not found in entity <NSSQLEntity EntityName id=2>

I use core data in my iOS App. I have two entities, "Commit", with attributes "commitID", "completionStatus", "contents" and "repeatStatus" as well as an entity "ToDoList" with the attribute "dateID". The two are connected via a relationship that relates many Commits to one ToDoList.
I get the following error every time. I have tried deleting and reinstalling the app, to no avail. I know this error is thrown after my application(application: didFinishLaunchingWithOptions:) method:
2016-05-07 10:54:14.131 CommitToday[1836:47383] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'keypath commitID not found in entity <NSSQLEntity ToDoList id=2>'
*** First throw call stack:
(
0 CoreFoundation 0x00000001027d7d85 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x000000010457bdeb objc_exception_throw + 48
2 CoreData 0x000000010242efff -[NSSQLGenerator newSQLStatementForRequest:ignoreInheritance:countOnly:nestingLevel:nestIsWhereScoped:] + 1583
3 CoreData 0x00000001023217e3 -[NSSQLGenerator newSQLStatementForFetchRequest:ignoreInheritance:countOnly:nestingLevel:nestIsWhereScoped:] + 35
4 CoreData 0x00000001024147b8 -[NSSQLAdapter _statementForFetchRequest:ignoreInheritance:countOnly:nestingLevel:] + 344
5 CoreData 0x000000010232167c -[NSSQLAdapter _newSelectStatementWithFetchRequest:ignoreInheritance:] + 316
6 CoreData 0x00000001023212f6 -[NSSQLCore newRowsForFetchPlan:] + 118
7 CoreData 0x0000000102320bac -[NSSQLCore objectsForFetchRequest:inContext:] + 524
8 CoreData 0x0000000102320549 -[NSSQLCore executeRequest:withContext:error:] + 377
9 CoreData 0x0000000102405eaf __65-[NSPersistentStoreCoordinator executeRequest:withContext:error:]_block_invoke + 3311
10 CoreData 0x000000010240f4dd gutsOfBlockToNSPersistentStoreCoordinatorPerform + 189
11 CoreData 0x00000001024005ed _perform + 221
12 CoreData 0x00000001023201b4 -[NSPersistentStoreCoordinator executeRequest:withContext:error:] + 500
13 CoreData 0x000000010231e973 -[NSManagedObjectContext executeFetchRequest:error:] + 579
14 CoreData 0x000000010244d6c2 __43-[NSFetchedResultsController performFetch:]_block_invoke + 258
15 CoreData 0x000000010240f4dd gutsOfBlockToNSPersistentStoreCoordinatorPerform + 189
16 libdispatch.dylib 0x00000001050143eb _dispatch_client_callout + 8
17 libdispatch.dylib 0x0000000104ff8ef5 _dispatch_barrier_sync_f_invoke + 393
18 CoreData 0x00000001023ff076 -[NSPersistentStoreCoordinator performBlockAndWait:] + 198
19 CoreData 0x0000000102366127 developerSubmittedBlockToNSManagedObjectContextPerform + 199
20 CoreData 0x0000000102365fee -[NSManagedObjectContext performBlockAndWait:] + 222
21 CoreData 0x000000010244d4bc -[NSFetchedResultsController performFetch:] + 524
22 CommitToday 0x00000001022404e4 _TFC11CommitToday14ViewController11viewDidLoadfT_T_ + 164
23 CommitToday 0x0000000102240d42 _TToFC11CommitToday14ViewController11viewDidLoadfT_T_ + 34
24 UIKit 0x000000010319a984 -[UIViewController loadViewIfRequired] + 1198
25 UIKit 0x00000001031defae -[UINavigationController _layoutViewController:] + 54
26 UIKit 0x00000001031df882 -[UINavigationController _updateScrollViewFromViewController:toViewController:] + 462
27 UIKit 0x00000001031df9f4 -[UINavigationController _startTransition:fromViewController:toViewController:] + 126
28 UIKit 0x00000001031e0c4d -[UINavigationController _startDeferredTransitionIfNeeded:] + 890
29 UIKit 0x00000001031e1d0b -[UINavigationController __viewWillLayoutSubviews] + 57
30 UIKit 0x0000000103390503 -[UILayoutContainerView layoutSubviews] + 248
31 UIKit 0x00000001030ba980 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 703
32 QuartzCore 0x0000000107aafc00 -[CALayer layoutSublayers] + 146
33 QuartzCore 0x0000000107aa408e _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 366
34 QuartzCore 0x0000000107aa3f0c _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 24
35 QuartzCore 0x0000000107a983c9 _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 277
36 QuartzCore 0x0000000107ac6086 _ZN2CA11Transaction6commitEv + 486
37 QuartzCore 0x0000000107ac67f8 _ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv + 92
38 CoreFoundation 0x00000001026fcc37 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 23
39 CoreFoundation 0x00000001026fcba7 __CFRunLoopDoObservers + 391
40 CoreFoundation 0x00000001026f211c CFRunLoopRunSpecific + 524
41 UIKit 0x0000000102ffaf21 -[UIApplication _run] + 402
42 UIKit 0x0000000102ffff09 UIApplicationMain + 171
43 CommitToday 0x000000010223c302 main + 114
44 libdyld.dylib 0x000000010504892d start + 1
45 ??? 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
From the error message:
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'keypath commitID not found in entity [NSSQLEntity ToDoList id=2]'
it seems to be trying to access an attribute named commitID on the ToDoList entity. That suggests you have a fetch or fetched results controller that is configured incorrectly.

Override Core Data to-many property and return a filtered set

I’ve got an NSManagedObject with a childNodes property in its model. Now I want to override the childNodes property and return a filtered version of it, but I keep getting crashes. Here’s what I’ve got in my NSMO subclass:
- (NSOrderedSet *)childNodes {
[self willAccessValueForKey:#“childNodes”];
NSMutableOrderedSet *result = [self primitiveChildNodes];
[self didAccessValueForKey:#"childNodes”];
NSArray *filteredResult = [[result array] myCustomArrayFilteringMethod]; // let’s say this returns the first half of the array, as a contrived example
return [NSOrderedSet orderedSetWithArray:filteredResults];
}
This works alright sometimes, but I’m finding crashes like: Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[NSOrderedSet objectsAtIndexes:]: index 24 in index set beyond bounds [0 .. 19]’ and I’m not sure why. Call stack seems to be related to mutating a collection, but I’m mutating a copy so I’m not sure what’s happening:
0 CoreFoundation __exceptionPreprocess + 165
1 libobjc.A.dylib objc_exception_throw + 48
2 CoreFoundation -[NSOrderedSet objectsAtIndexes:] + 952
3 Foundation NSKeyValueWillChangeByOrderedToManyMutation + 568
4 Foundation NSKeyValueWillChange + 383
5 Foundation -[NSObject(NSKeyValueObserverNotification) willChange:valuesAtIndexes:forKey:] + 557
6 CoreData -[NSManagedObject(_NSInternalMethods) _excludeObject:fromPropertyWithKey:andIndex:] + 526
7 CoreData -[NSManagedObject(_NSInternalMethods) _maintainInverseRelationship:forProperty:oldDestination:newDestination:] + 254
8 CoreData -[NSManagedObject(_NSInternalMethods) _didChangeValue:forRelationship:named:withInverse:] + 567
9 Foundation NSKeyValueNotifyObserver + 347
10 Foundation NSKeyValueDidChange + 466
11 Foundation -[NSObject(NSKeyValueObserverNotification) didChangeValueForKey:] + 118
12 CoreData -[NSManagedObject didChangeValueForKey:] + 135
13 CoreData -[NSManagedObject(_NSInternalMethods) _updateFromRefreshSnapshot:includingTransients:] + 758
14 CoreData -[NSManagedObjectContext(_NestedContextSupport) _copyChildObject:toParentObject:fromChildContext:] + 567
15 CoreData -[NSManagedObjectContext(_NestedContextSupport) _parentProcessSaveRequest:inContext:error:] + 1103
16 CoreData __82-[NSManagedObjectContext(_NestedContextSupport) executeRequest:withContext:error:]_block_invoke + 364
17 CoreData internalBlockToNSManagedObjectContextPerform + 84
18 libdispatch.dylib _dispatch_client_callout + 8
19 libdispatch.dylib _dispatch_barrier_sync_f_slow_invoke + 284
20 libdispatch.dylib _dispatch_client_callout + 8
21 libdispatch.dylib _dispatch_main_queue_callback_4CF + 1738
22 CoreFoundation __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 9
23 CoreFoundation __CFRunLoopRun + 2073
24 CoreFoundation CFRunLoopRunSpecific + 488
25 GraphicsServices GSEventRunModal + 161
26 UIKit UIApplicationMain + 171
27 My app main + 111
28 libdyld.dylib
Any suggestions? I can’t quite figure this one out.
Just don't. Add a different method which returns a filtered copy of the original relationship. Also, for the implementation just iterate the collection and add the items you want to keep to an entirely new collection, don't copy and filter.
The crash is because the array you're filtering is actually backed by the datastore, so as you filter it it's changing the contents you're iterating with the filter, and it's screwing up the original relationship.

Crash when Fetched Results Controller updates table after saving a background MOC

I have a tableView hooked up to a FRC (Fetched Results Controller) , I also have two contexts , namely backgroundContext initialised in a private queue and a mainContext initialised on the main queue. I also have setup the didSaveNotification to pass the objects from one context to another. When ever i save some data in the backgroundContext it saves successfully and FRC updates ,but if i repeat the process again the app crashes with an error
'The left hand side for an ALL or ANY operator must be either an
NSArray or an NSSet.'
The saving is done through a form which is presented modally. The same viewController works fine if presented in other viewControllers . but crashes only in one particular one. But again other that presenting the Form no other extra stuff is being done.
Here's my entire crash report.
Terminating app due to uncaught exception
'NSInvalidArgumentException', reason: 'The left hand side for an ALL
or ANY operator must be either an NSArray or an NSSet.'
* First throw call stack: ( 0 CoreFoundation 0x0000000103575495 exceptionPreprocess + 165 1 libobjc.A.dylib
0x0000000102fbb99e objc_exception_throw + 43 2 Foundation
0x00000001003c706b -[NSPredicateOperator
performOperationUsingObject:andObject:] + 826 3 Foundation
0x00000001003c6c1e -[NSComparisonPredicate
evaluateWithObject:substitutionVariables:] + 314 4 Foundation
0x00000001003c6ae2 -[NSPredicate evaluateWithObject:] + 19 5
CoreData 0x0000000102d61d06
-[NSFetchedResultsController(PrivateMethods) _objectInResults:] + 102 6 CoreData 0x0000000102d630f7
-[NSFetchedResultsController(PrivateMethods) _preprocessUpdatedObjects:insertsInfo:deletesInfo:updatesInfo:sectionsWithDeletes:newSectionNames:treatAsRefreshes:]
+ 519 7 CoreData 0x0000000102d642d5 -[NSFetchedResultsController(PrivateMethods) _managedObjectContextDidChange:] + 1781 8 CoreFoundation 0x00000001035cad9c
__CFNOTIFICATIONCENTER_IS_CALLING_OUT_TO_AN_OBSERVER + 12 9 CoreFoundation 0x000000010352d51d
_CFXNotificationPost + 2381 10 Foundation 0x000000010035b7fa -[NSNotificationCenter
postNotificationName:object:userInfo:] + 68 11 CoreData
0x0000000102c9048a
-[NSManagedObjectContext(_NSInternalNotificationHandling) _postObjectsDidChangeNotificationWithUserInfo:] + 74 12 CoreData 0x0000000102d16c8b
-[NSManagedObjectContext(_NSInternalChangeProcessing) _createAndPostChangeNotification:withDeletions:withUpdates:withRefreshes:]
+ 331 13 CoreData 0x0000000102c8c9cc -[NSManagedObjectContext(_NSInternalChangeProcessing) _postRefreshedObjectsNotificationAndClearList] + 108 14 CoreData 0x0000000102c8c5e4
-[NSManagedObjectContext(_NSInternalChangeProcessing) _processRecentChanges:] + 2804 15 CoreData 0x0000000102c663cb _performRunLoopAction + 267 16 CoreFoundation
0x0000000103540dc7
CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION + 23 17 CoreFoundation 0x0000000103540d37
__CFRunLoopDoObservers + 391 18 CoreFoundation 0x0000000103520522 __CFRunLoopRun + 946 19 CoreFoundation
0x000000010351fd83 CFRunLoopRunSpecific + 467 20 GraphicsServices
0x00000001037ecf04 GSEventRunModal + 161 21 UIKit
0x00000001011bde33 UIApplicationMain + 1010 22 Expense_Manager
0x0000000100001d13 main + 115 23 libdyld.dylib
0x000000010420c7e1 start + 0 ) libc++abi.dylib: terminating with
uncaught exception of type NSException
Thanks in advance.
Okay i actually found out why this was happening a few days ago. There was a notification being fired off when the form dismissed which reloaded a tableView from another viewController hooked up to an FRC sharing the same context. Once I removed itself as an observer in viewDidDisappear it did not crash. :) I hope this helps incase someone is facing the same problem.

Resources