Searching an NSArray of NSDictionaries

NSPredicate is the simplest way to do it.

Given Data like this:

NSArray *theArray = @[@{@"id":1,"name":@"one"},@{@"id":2,"name":@"two"},@{@"id":3,"name":@"three"}];
NSPredicate *p = [NSPredicate predicateWithFormat:@"id = 291"]; //fiber
NSArray *matchedDicts = [theArray filteredArrayUsingPredicate:p];

There is much more to NSPredicate. I used exact matching, but matching with BEGINSWITH, CONTAINS, ENDSWITH, and LIKE. In some examples you’ll also see [c] or [cd] next to these keywords. The ‘c’ means it searches case insensitively and the ‘d’ means that an ‘o’ with an umlaut is still just an ‘o’.

Asterix Options

NSString *asterixOnVar;
NSString * asterixInAir;
NSString* asterixOnTypdef;

They all declare that it is a pointer to an NSString. There is no difference except readability. I prefer the first version because it shows the type and it is clear that the variable is a pointer.

Sorting Segues Sanely

There are three kinds of segues, push, modal and custom. You’ll probably most often use the ‘push’ method. It is incredibly useful in making storyboards do stuff.

Primarily there are two ways to invoke a segue. One is to rig up a button in Interface Builder that triggers a segue. The other is to invoke the segue on your own. I think that a lot of times I need to validate what’s on the screen before I can release it to the next controller. Therefore I need to do it myself.

Also you need to pass information back and forth, which will be taken care of by setting variables in the method:

-(void) prepareForSegue:(UIStoryBoardSegue *)segue sender:(id)sender {

Continue reading