Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/118.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c 将核心数据值放入数组中_Objective C_Ios_Uitableview_Core Data - Fatal编程技术网

Objective c 将核心数据值放入数组中

Objective c 将核心数据值放入数组中,objective-c,ios,uitableview,core-data,Objective C,Ios,Uitableview,Core Data,我需要将使用从核心数据图获取请求检索到的值放入数组中,但不完全确定如何执行此操作 我正在使用以下命令执行提取: NSString *entityName = @"Project"; // Put your entity name here NSLog(@"Setting up a Fetched Results Controller for the Entity named %@", entityName); // 2 - Request that En

我需要将使用从核心数据图获取请求检索到的值放入数组中,但不完全确定如何执行此操作

我正在使用以下命令执行提取:

    NSString *entityName = @"Project"; // Put your entity name here
        NSLog(@"Setting up a Fetched Results Controller for the Entity named %@", entityName);

        // 2 - Request that Entity
        NSFetchRequest *request = [NSFetchRequest fetchRequestWithEntityName:entityName];

        // 3 - Filter it if you want
        request.predicate = [NSPredicate predicateWithFormat:@"belongsToProject = %@", _selectedProject];

        // 4 - Sort it if you want
        request.sortDescriptors = [NSArray arrayWithObject:[NSSortDescriptor sortDescriptorWithKey:@"dateTaken"
                                                                                         ascending:YES
                                                                                          selector:@selector(localizedCaseInsensitiveCompare:)]];
        // 5 - Fetch it
        self.fetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:request
                                                                            managedObjectContext:self.managedObjectContext
                                                                              sectionNameKeyPath:nil
                                                                                       cacheName:nil];


[self performFetch];
如您所见,我正在使用NSPredicate筛选返回的值

如何将这些值放入数组中,并在它们位于数组中后为实体选择单个属性,例如project.description或project.name

多亏了Eimantas,我在一个数组中获得了对象,但是我仍然需要做两件事:

  • 循环遍历数组并将数据输出到一些HTML中
  • 分别从数组中选择属性,例如项目描述
  • 我使用以下for循环来执行第一步:

    for (int i=0; i < [projectListArray count]; i++) 
    {
            NSString *tmp = (NSString *)[projectListArray objectAtIndex:i];
    }
    

    似乎我没有递增?

    [self.fetchedResultsController fetchedObject]
    返回已获取对象的数组

    更新

    最好使用快速枚举,而不是
    for
    循环:

    for (Project *project in projectListArray) {
        NSString *projectDescription = [project valueForKey:@"description"];
    }
    

    您之所以会出现异常,是因为您正在将对象强制转换为
    NSString
    ,而它是指向(我猜想)项目的指针。

    非常棒,谢谢您Eimantas。如果你不介意帮忙的话,我还有一件事要做?我已经更新了我原来的问题。
    for (Project *project in projectListArray) {
        NSString *projectDescription = [project valueForKey:@"description"];
    }