NSPredicate: Fetch one of each kind

后端 未结 5 1887
眼角桃花
眼角桃花 2021-02-02 11:49

I want to create an NSFetchRequest for objects like this:

The Object is Car which has an attribute color

5条回答
  •  温柔的废话
    2021-02-02 12:26

    try this one:

        NSFetchRequest *fetchRequest = [NSFetchRequest fetchRequestWithEntityName:@"Cars"];
        NSArray *arrayValues = [self.managedObjectContext executeFetchRequest:fetchRequest error:&error];
    
    if (arrayValues.count != 0) {
         NSDictionary *result = [NSDictionary dictionaryWithObjects:arrayValues
                               forKeys:[arrayValues valueForKey:@"color"]];
         return [result allValues];
    }
    

提交回复
热议问题