I have NSArray of custom objects with id property and an another NSArray of NSString. The second array is a list of ids. So I want to get array of object arranged by order in second array.
1 Answer
use an NSSortDescriptor, or sort with a block that performs the comparison in the other array.
How to sort an NSMutableArray with custom objects in it?
Update:
Since neither the objects nor the list of ids have a reference to the other, there is no efficient way to reorder. Without introducing a new collection, you will have to iterate through one of the lists many many times.
The only way you can do this efficiently is to change your architecture and use a hash map of some kind such as an NSDictionary so you can quickly reference an object from the id. Alternatively you can use an ordered dictionary.
@property ... id? Sounds like a bad idea in Objective-C. Anyway, what have you tried?