Getting an NSArray of a single attribute from an NSArray

后端 未结 3 819
一整个雨季
一整个雨季 2021-01-02 09:08

I am facing a very regular scenario.

I have an NSArray which has object of a custom type, say Person. The Person class has the attributes: firstName, lastName and ag

3条回答
  •  耶瑟儿~
    2021-01-02 10:03

    NSArray will handle this for you using KVC

    NSArray *people ...;
    NSArray *firstName = [people valueForKey:@"firstName"];
    

    This will give you an array of the firstName values from each entry in the array

提交回复
热议问题