Logo

Programming-Idioms

History of Idiom 28 > diff from v59 to v60

Edit summary for version 60 by OC:
New Obj-C implementation by user [OC]

Version 59

2020-05-21, 20:22:59

Version 60

2020-10-10, 20:34:45

Idiom #28 Sort by a property

Sort elements of array-like collection items in ascending order of x.p, where p is a field of the type Item of the objects in items.

Idiom #28 Sort by a property

Sort elements of array-like collection items in ascending order of x.p, where p is a field of the type Item of the objects in items.

Variables
items,x,p
Variables
items,x,p
Imports
@import Foundation;
Code
[items sortedArrayUsingDescriptors:@[[NSSortDescriptor sortDescriptorWithKey:@"p" ascending:YES]]]
Comments bubble
Presumed the array contains any kind of objects with a property p (e.g., maps with key p, etc.) ObjC arrays very rarely contain structs; for such case a plain-C solution would be better, and of course possible