Best way to sort an NSArray of NSDictionary objects?

Use NSSortDescriptor like this.. NSSortDescriptor * descriptor = [[NSSortDescriptor alloc] initWithKey:@”interest” ascending:YES]; stories = [stories sortedArrayUsingDescriptors:@[descriptor]]; recent = [stories copy]; stories is the array you want to sort. recent is another mutable array which has sorted dictionary values. Change the @”interest” with the key value on which you have to sort. All the best

Is there an easy way to iterate over an NSArray backwards?

To add on the other answers, you can use -[NSArray reverseObjectEnumerator] in combination with the fast enumeration feature in Objective-C 2.0 (available in Leopard, iPhone): for (id someObject in [myArray reverseObjectEnumerator]) { // print some info NSLog([someObject description]); } Source with some more info: http://cocoawithlove.com/2008/05/fast-enumeration-clarifications.html

I want to sort an array using NSSortDescriptor

Take a look here: Creating and Using Sort Descriptors You can compare as case-insensitive. NSSortDescriptor *sorter = [[[NSSortDescriptor alloc] initWithKey:@”w” ascending:YES selector:@selector(localizedCaseInsensitiveCompare:)] autorelease]; NSArray *sortDescriptors = [NSArray arrayWithObject: sorter]; [mGlossaryArray sortUsingDescriptors:sortDescriptors];

Check if NSString instance is contained in an NSArray

Yes, hard-coded NSStrings (string literals) (that is any @”…” in your source code) are turned into strings that exist indefinitely while your process is running. However NSArray‘s containsObject: methods calls isEqual: on its objects, hence even a dynamically created string such as [NSString stringWithFormat:@”%d”, 2] would return YES in your sample snippet. This is because … Read more

What is the BOOL *stop argument for enumerateObjectsUsingBlock: used for?

The stop argument to the Block allows you to stop the enumeration prematurely. It’s the equivalent of break from a normal for loop. You can ignore it if you want to go through every object in the array. for( id obj in arr ){ if( [obj isContagious] ){ break; // Stop enumerating } if( ![obj … Read more

What’s the best way to put a c-struct in an NSArray?

NSValue doesn’t only support CoreGraphics structures – you can use it for your own too. I would recommend doing so, as the class is probably lighter weight than NSData for simple data structures. Simply use an expression like the following: [NSValue valueWithBytes:&p objCType:@encode(Megapoint)]; And to get the value back out: Megapoint p; [value getValue:&p];