如何从_NSCoreDataTaggedObjectID获取对象或值

Jee*_*eef 6 core-data ios ios7

我跟随苹果的例子:(https://developer.apple.com/library/ios/documentation/DataManagement/Conceptual/CoreDataSnippets/Articles/fetchExpressions.html)来获取不同的"值"

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"];

    }
Run Code Online (Sandbox Code Playgroud)

当我objects[1]在调试器中探索值时,我看到我的密钥是_PFEncodedString *,我的值是_NSCoreDataTaggedObjectID * 我不清楚的是如何实际上从我的数据类型中取回我的CoreData对象.

Nik*_*osM 5

我刚刚看到这篇文章,正在寻找有关此问题的答案。因此,如果有人遇到此问题,您可以通过在 NSManagedObjectContext 的objectWithID:方法中传递结果字典中的值来获取实际的NSManagedObject

所以类似的东西:

NSManagedObjectID *managedObjectID = [dict objectForKey:@"fetched_property_name"]
NSManagedObject *managedObject = [moc objectWithID:managedObjectID]
Run Code Online (Sandbox Code Playgroud)