How to get an object or value from _NSCoreDataTaggedObjectID

I followed the example using apple: ( https://developer.apple.com/library/ios/documentation/DataManagement/Conceptual/CoreDataSnippets/Articles/fetchExpressions.html ) to get excellent "values"

NSEntityDescription *ahrsMessage = [NSEntityDescription entityForName:@"AHRSMessage" inManagedObjectContext:self.managedObjectContext]; NSFetchRequest *distinctFetch = [NSFetchRequest new]; [distinctFetch setEntity:ahrsMessage]; [distinctFetch setResultType:NSDictionaryResultType]; [distinctFetch setReturnsDistinctResults:YES]; [distinctFetch setPropertiesToFetch:@[@"flightRecordings"]]; NSError *e = nil; id requestedValue = nil; NSArray *objects = [self.managedObjectContext executeFetchRequest:distinctFetch error:&e]; if (objects == nil) { NSLog(@"ERROR"); } for (NSDictionary *dict in objects) { NSLog(@"dict: %@", dict); [dict objectForKey:@"flightRecordings"]; } 

When I examine the value of objects[1] in the debugger, I see that my key is _PFEncodedString * and my value is _NSCoreDataTaggedObjectID * . I do not understand how to actually return my CoreData object from this data type.

+6
source share
1 answer

I just stumbled upon this post, looking for an answer about it myself. Therefore, if someone encounters this problem, you can get the actual NSManagedObject by passing the value from the result dictionary in the NSManagedObjectContext objectWithID: method.

So something like:

 NSManagedObjectID *managedObjectID = [dict objectForKey:@"fetched_property_name"] NSManagedObject *managedObject = [moc objectWithID:managedObjectID] 
+4
source

Source: https://habr.com/ru/post/972958/


All Articles