Baiscally 我想用核心数据查询的结果更新 UILabel。我有一个带有以下文本的 UILabel “root has X credits”。我想在核心数据中搜索实体“帐户”,然后细化搜索以查找“根”帐户,然后细化搜索“根”帐户中的属性“信用”。最后,我想更新 UILabel 以读取“root has 0 credits”(或者 Core Data 查询描述的许多学分。
到目前为止,我有以下代码,
- (void)rootCreditAmount {
// Core Data - root credit amount
NSFetchRequest *request = [[NSFetchRequest alloc] init];
// define our table / entity to use
NSEntityDescription *entity = [NSEntityDescription entityForName:@"Account" inManagedObjectContext:_managedObjectContext];
[request setEntity:entity];
// filter results to just root user
NSPredicate *username = [NSPredicate predicateWithFormat:@"root"];
[request setPredicate:username];
// fetch records and handle error
NSError *error;
NSMutableArray *mutableFetchResults = [[_managedObjectContext executeFetchRequest:request error:& error] mutableCopy];
if (!mutableFetchResults) {
// handle error.
// should advise user to restart
}
NSLog(@"mutablefetchresults = %@",mutableFetchResults);
}
不用说,这段代码目前正在导致我的应用程序崩溃。