cocoa - 核心数据返回不正确的值(尽管几乎正确)

标签 cocoa core-data nspredicate

好的,所以我向核心数据请求一条记录(userKey),该记录中是我正在提取的公钥,但是,公钥最终是 90% 正确的,但在开头有一些额外的字符,并且被封装在括号。

我认为我的问题是我得到的是指针而不是来自 userMatches 的数据。任何指导将不胜感激。

AppDelegate *appdelagate = [[UIApplication sharedApplication]delegate];
context = [appdelagate managedObjectContext];

NSEntityDescription *entitydesc = [NSEntityDescription entityForName:@"KeyData" inManagedObjectContext:context];
NSFetchRequest *request = [[NSFetchRequest alloc]init];

predicate = [NSPredicate predicateWithFormat:@"userKeyCD = %@", userKey];
[request setEntity:entitydesc];
[request setPredicate:predicate];

userMatches = [context executeFetchRequest:request error:&error];

NSString *publicKey = [userMatches valueForKey:@"publicKeyCD"];

最佳答案

好的,我将最后一行更改为这一行,效果很好;

    NSString *publicKey = [[userMatches objectAtIndex:0] valueForKey:@"publicKeyCD"];

我没有展示它是如何定义的,但 userMatches 是一个 NSArray (抱歉)。它在代码中以类似的方式使用;

   NSArray *userMatches = [context executeFetchRequest:request error:&error];

现在我想这是一个正确的数组类型吗?

关于cocoa - 核心数据返回不正确的值(尽管几乎正确),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16220444/

相关文章:

ios - 如何一次删除多个核心数据对象?

swift - "Value of tuple type ' (String, JSON )' has no member ' subscript' "在Xcode中指的是什么?

xcode - 核心数据可转换属性不适用于 NSPredicate

ios - 如何使用NSPredicate以与完整NSArray相同的顺序对NSSet子集进行排序?

objective-c - 编写 NSPredicate 格式字符串来测试多个属性的更短方法?

cocoa - NSMenu 不开始跟踪

cocoa - NSSavePanel 处理操作

ios - 如何在核心数据的后台线程中保存到托管对象上下文

xcode - 找不到框架问题

cocoa - 在 Xcode 4.2 中使用基于 View 的表格 View 创建的应用程序可以在 OS X 10.5-10.6 上运行吗?