I have an array of CoreData objects, each object is Person
and each Person
has an age
attribute which is of type Integer32.
My array is filled with Person
objects. I want to sort my array by their age
attribute.
How can I do this?
It should be as simple as:
NSArray *sortDescriptors = @[
[NSSortDescriptor sortDescriptorWithKey:@"age" ascending:YES]
];
NSArray *sortedPeople = [people sortedArrayUsingDescriptors:sortDescriptors];
NSLog(@"%@", sortedPeople);
This will work regardless of whether you do or do not choose to "Use scalar properties for primitive data types" when creating your NSManagedObject
subclass (if you decide to even create them)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With