好的,所以我向核心数据请求一条记录(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/