In a Core Data fetched property expression, apparently $FETCH_SOURCE
resolves to an object ID instead of the object itself. This caused an exception "class is not key-value coding...". Which is true since it's the object that responds to that key.
I would like to use the source object's property value(s) as part of a fetched property's predicate.
Any idea how to fix this?
*** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<_NSObjectID_48_0 0x10101b200> valueForUndefinedKey:]: this class is not key value coding-compliant for the key messageType.'
*** First throw call stack:
(
0 CoreFoundation 0x00007fff92ba00c6 __exceptionPreprocess + 198
1 libobjc.A.dylib 0x00007fff8f85e3f0 objc_exception_throw + 43
2 CoreFoundation 0x00007fff92c34249 -[NSException raise] + 9
3 Foundation 0x00007fff9518b08c -[NSObject(NSKeyValueCoding) valueForUndefinedKey:] + 238
4 Foundation 0x00007fff950d2df9 -[NSObject(NSKeyValueCoding) valueForKey:] + 400
5 Foundation 0x00007fff950f36a8 -[NSObject(NSKeyValueCoding) valueForKeyPath:] + 341
6 Foundation 0x00007fff950a3489 -[NSFunctionExpression expressionValueWithObject:context:] + 751
7 CoreData 0x00007fff88cbbdda -[NSSQLSimpleWhereIntermediate initWithPredicate:inScope:] + 618
8 CoreData 0x00007fff88cbb672 -[NSSQLGenerator generateWhereIntermediatesInContext:] + 162
9 CoreData 0x00007fff88cbb010 -[NSSQLGenerator generateIntermediatesForFetchInContext:countOnly:] + 416
10 CoreData 0x00007fff88cb7d30 -[NSSQLGenerator newSQLStatementForFetchRequest:ignoreInheritance:countOnly:nestingLevel:] + 400
11 CoreData 0x00007fff88cb7a97 -[NSSQLAdapter _newSelectStatementWithFetchRequest:ignoreInheritance:] + 471
12 CoreData 0x00007fff88cb76b6 -[NSSQLCore newRowsForFetchPlan:] + 118
13 CoreData 0x00007fff88cb6f2e -[NSSQLCore objectsForFetchRequest:inContext:] + 526
14 CoreData 0x00007fff88cb6a91 -[NSSQLCore executeRequest:withContext:error:] + 225
15 CoreData 0x00007fff88cb5f72 -[NSPersistentStoreCoordinator executeRequest:withContext:error:] + 2114
16 CoreData 0x00007fff88cb4309 -[NSManagedObjectContext executeFetchRequest:error:] + 537
17 CoreData 0x00007fff88cfca4e -[NSManagedObjectContext(_NestedContextSupport) _parentObjectsForFetchRequest:inContext:error:] + 414
18 CoreData 0x00007fff88d3072a __82-[NSManagedObjectContext(_NestedContextSupport) executeRequest:withContext:error:]_block_invoke_0 + 634
19 libdispatch.dylib 0x00007fff8b2710b6 _dispatch_client_callout + 8
20 libdispatch.dylib 0x00007fff8b272723 _dispatch_barrier_sync_f_invoke + 39
21 CoreData 0x00007fff88cfc87c _perform + 172
22 CoreData 0x00007fff88cfc6c2 -[NSManagedObjectContext(_NestedContextSupport) executeRequest:withContext:error:] + 354
23 CoreData 0x00007fff88cb4309 -[NSManagedObjectContext executeFetchRequest:error:] + 537
24 CoreData 0x00007fff88d0481e -[NSFaultHandler retainedFulfillAggregateFaultForObject:andRelationship:withContext:] + 254
25 CoreData 0x00007fff88d7faa8 -[_NSFaultingMutableArray willRead] + 120
26 CoreData 0x00007fff88d7fe99 -[_NSFaultingMutableArray count] + 25
27 CoreFoundation 0x00007fff92b82e69 -[NSArray lastObject] + 25
28 Scuttlebutt 0x0000000100041aab -[BSMessageCellView setObjectValue:] + 283
29 AppKit 0x00007fff936ca006 -[NSTableRowData _addViewToRowView:atColumn:row:] + 696
30 AppKit 0x00007fff936c9b5f -[NSTableRowData _addViewsToRowView:atRow:] + 151
31 AppKit 0x00007fff936c80f5 -[NSTableRowData _addRowViewForVisibleRow:withPriorView:] + 415
32 AppKit 0x00007fff936c7e7a -[NSTableRowData _addRowViewForVisibleRow:withPriorRowIndex:inDictionary:withRowAnimation:] + 272
33 AppKit 0x00007fff936c7149 -[NSTableRowData _unsafeUpdateVisibleRowEntries] + 740
34 AppKit 0x00007fff936c6ce1 -[NSTableRowData updateVisibleRowViews] + 119
35 AppKit 0x00007fff936da8b3 -[NSTableRowData _idleUpdateVisibleRows] + 66
36 CoreFoundation 0x00007fff92b5cdc4 __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 20
37 CoreFoundation 0x00007fff92b5c8dd __CFRunLoopDoTimer + 557
38 CoreFoundation 0x00007fff92b420c9 __CFRunLoopRun + 1513
39 CoreFoundation 0x00007fff92b416e2 CFRunLoopRunSpecific + 290
40 HIToolbox 0x00007fff9427e0a4 RunCurrentEventLoopInMode + 209
41 HIToolbox 0x00007fff9427de42 ReceiveNextEventCommon + 356
42 HIToolbox 0x00007fff9427dcd3 BlockUntilNextEventMatchingListInMode + 62
43 AppKit 0x00007fff93544b13 _DPSNextEvent + 685
44 AppKit 0x00007fff935443d2 -[NSApplication nextEventMatchingMask:untilDate:inMode:dequeue:] + 128
45 AppKit 0x00007fff9353b773 -[NSApplication run] + 517
46 AppKit 0x00007fff934e01a6 NSApplicationMain + 869
47 Scuttlebutt 0x0000000100002225 main + 53
48 Scuttlebutt 0x00000001000021e4 start + 52
49 ??? 0x0000000000000003 0x0 + 3
)
This is what came up when I tried dumping the offending object's details -- quite visible that it's an object ID instead of the object itself.
(lldb) expression (NSString*) [(id)0x10101b200 description]
(NSString *) $0 = 0x0000000108b03880 @"0x10101b200 <x-coredata://8F1FBB6B-505B-4169-A9D0-10D48CE5D4DC/YammerMessage/p101>"
(lldb) expression (Class) [(id)0x10101b200 class]
(Class) $2 = _NSObjectID_48_0
Fetched Properties in Core Data are properties that return an array value from a predicate. A fetched property predicate is a Core Data query that evaluates to an array of results.
Fetching Data From CoreData We have created a function fetch() whose return type is array of College(Entity). For fetching the data we just write context. fetch and pass fetchRequest that will generate an exception so we handle it by writing try catch, so we fetched our all the data from CoreData.
A description of search criteria used to retrieve data from a persistent store.
A compact, universal identifier for a managed object.
You can set the result type of a NSFetchRequest with the method setResultType:, to get NSManagedObjects, you have to set it to NSManagedObjectResultType.
NSFetchRequest *fetchrequest = [[NSFetchRequest alloc] init];
[fetchRequest setResultType:NSManagedObjectResultType];
If you use the CoreData editor of XCode, you can choose the result type by selecting the fetch request and navigating to the 'Data Model Inspektor' tab in the right utilities tab.
Edit: See this screenshot
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With