核心数据返回不正确的值(虽然几乎是正确的)
问题描述:
好吧,所以我要求核心数据记录(userKey),该记录是一个PublicKey,我正在提取,但是,publicKey结束了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];
现在我想想它是一个数组的正确类型?
我已经在模拟器上检查了数据库,并且其中的值是正确的。 – 2013-04-25 16:54:58
该代码没有错(除非你没有检查'executeFetchRequest'的返回值,你只是假设它工作)。首先,这个价值是如何进入数据存储的? – 2013-04-25 18:09:18
谢谢你的采访。是的,目前我所有的是NSLogs的错误(我编辑出来),错误是(空)。 – 2013-04-26 08:21:05