相关疑难解决方法(0)

计算核心数据属性的最大值 - NSCFNumber错误

我需要找出核心数据实体的属性的最大值.

我仍然坚定地在Cocoa学习曲线中,这是一个我正在学习的简单测试应用程序.

该应用程序从文本文件中导入财富,并在屏幕上显示一个表格.导入在单独的后台线程中完成.

我在网上找到了这个代码,我试图让它起作用:

- (double)getMaxID  
{  
    NSLog(@"in getMaxID");  // debug  

    // Use a new moc with the original persistentStoreCoordinator to ensure thread safety  
    NSManagedObjectContext *moc = [[NSManagedObjectContext alloc] init];  
    [moc setPersistentStoreCoordinator:[[self delegate] persistentStoreCoordinator]];  

    // Create fetch  
    NSFetchRequest *fetch = [[NSFetchRequest alloc] init];  
    [fetch setEntity:[NSEntityDescription entityForName:@"Fortune"   inManagedObjectContext:moc]];  
    [fetch setResultType:NSDictionaryResultType];  

    // Expression for Max ID  
    NSExpression *keyPathExpression = [NSExpression expressionForKeyPath:@"id"];  
    NSExpression *minExpression = [NSExpression expressionForFunction:@"max:" arguments:  [NSArray arrayWithObject:keyPathExpression]];  
    NSExpressionDescription *expressionDescription = [[NSExpressionDescription alloc] init];  
    [expressionDescription setName:@"maxID"];  
    [expressionDescription setExpression:minExpression];  
    [expressionDescription setExpressionResultType:NSDoubleAttributeType];  
    [fetch …
Run Code Online (Sandbox Code Playgroud)

core-data objective-c

15
推荐指数
3
解决办法
1万
查看次数

标签 统计

core-data ×1

objective-c ×1