Conditionally start at different places in storyboard from AppDelegate

I’m surprised at some of the solutions being suggested here. There’s really no need for dummy navigation controllers in your storyboard, hiding views & firing segues on viewDidAppear: or any other hacks. If you don’t have the storyboard configured in your plist file, you must create both the window and the root view controller yourself … Read more

NSString retain Count

The compiler is smarter than you. It sees @”Hello world” and thinks “Aha! A constant string!” It then sees [[NSString alloc] initWithString:@”Hello world!”] and thinks “Aha! An immutable object created with a constant string!” It then collapses both of them down into a single NSConstantString, which has a retainCount of UINT_MAX, so that it can … Read more

Animating an image view to slide upwards

For non-autolayout storyboards/NIBs, your code is fine. By the way, it’s now generally advised that you animate using blocks: [UIView animateWithDuration:3.0 animations:^{ self.logo.center = CGPointMake(self.logo.center.x, self.logo.center.y – 100.0); }]; Or, if you want a little more control over options and the like, you can use: [UIView animateWithDuration:3.0 delay:0.0 options:UIViewAnimationCurveEaseInOut animations:^{ self.logo.center = CGPointMake(self.logo.center.x, self.logo.center.y – … Read more

NSString (hex) to bytes

Fastest NSString category implementation that I could think of (cocktail of some examples): – (NSData *)dataFromHexString { const char *chars = [self UTF8String]; int i = 0, len = self.length; NSMutableData *data = [NSMutableData dataWithCapacity:len / 2]; char byteChars[3] = {‘\0′,’\0′,’\0’}; unsigned long wholeByte; while (i < len) { byteChars[0] = chars[i++]; byteChars[1] = chars[i++]; … Read more

Parsing XML in Cocoa

Here’s how it works: There’s a class called NSXMLParser. It’s used to parse XML files. However, NSXMLParser is stupid. All it knows how to do is parse XML, but it doesn’t know what it’s supposed to do with the information it finds. Enter a delegate. A delegate is like a nanny. Since the XMLParser doesn’t … Read more

filtering NSArray into a new NSArray in Objective-C

NSArray and NSMutableArray provide methods to filter array contents. NSArray provides filteredArrayUsingPredicate: which returns a new array containing objects in the receiver that match the specified predicate. NSMutableArray adds filterUsingPredicate: which evaluates the receiver’s content against the specified predicate and leaves only objects that match. These methods are illustrated in the following example. NSMutableArray *array … Read more