NSPredicate: Fetch one of each kind

后端 未结 5 1885
眼角桃花
眼角桃花 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:20

    Did you tried to use valueForKeyPath ? You can do something like that in the array that NSPredicate provide to you.

    NSArray* distinctColors = [cars valueForKeyPath:@"@distinctUnionOfObjects.color"];
    

    It will return to you the distinct colors that you have, I do not know if it is what you want, but with the colors you can do something like @Anupdas told:

提交回复
热议问题