Book Review: iOS SDK Development

iOS SDK DevelopmentI recently got my hands on a review copy of the new book, “iOS SDK Development”, by Chris Adamson and Bill Dudney. The book was just published at the end of November 2012, and it’s chock full of the latest techniques and technologies in Xcode and Objective-C.

The book is appropriate for developers who are new to the iOS platform, though the breakneck pace may be overwhelming. I wouldn’t recommend it for anyone brand new to software development in general. So if you’re an experienced developer and want to add iOS development to your toolbox, this is a great place to start. But it is not a “Learn to program” book.

As an experienced iOS developer, I was impressed by how current many of the concepts in this book were. Of course, they cover the basics like Table Views and hooking up UI elements, but they also introduce and demonstrate a lot of the newer SDK and language features too. They build interfaces with Storyboard and Auto-Layout. They use UIDocument and iCloud to store data. Also covered is the new Automation capabilities of the Instruments tool, which can enable you to run automated user interface tests on your apps. This is definitely an iOS 6 book.

Something I really appreciated was that the authors explained what could go wrong in many situations. They explained how things could break, and especially how to fix them. This is sorely missing from most development books.

The authors also walk you through the entire development cycle and offer informative chapters on testing and deploying your apps, including a mention of Provisioning Profile hell.

“iOS SDK Development” manages to cover a lot of territory in less than 300 pages, and by necessity they only offer a taste of some SDK features, like iCloud, and pass over others completely, like Core Data. I learned a few new tricks from this book and I’m glad I read it. I’d recommend it especially to developers who are new to the iOS world, but even veterans could learn a thing or two from this one.

Advertisements

Adding Array Subscripting To Your Classes in Objective-C

Xcode 4.4 added some great new literals syntax for collection classes and numbers, so now you can write NSArray *array = [@”one”, @”two”, @”three”]; And you can access those elements with array-style subscripting like this NSString *s = array[1];

On it own, that’s great, but there’s more under the surface here. When you write array[1], the compiler translates that into a method call named objectAtIndexSubscript:, which is implemented by NSArray. The cool part is that you can implement this method in your own classes, and then use subscripting on instances of your classes. You can also implement the sister method: setObject:atIndexedSubscript: to set values.

The code below is a simple example of how you could use this:

// Header

@interface ItemCollection : NSObject

@property (strong) NSMutableArray *list;

// Suport for Array-style subscripting. Ex. items[4] = @”hello”;

– (void)setObject:(id)anObject atIndexedSubscript:(NSUInteger)idx;

– (id)objectAtIndexedSubscript:(NSUInteger)idx;

@end

// Implementation

@implementation ItemCollection

– (void)setObject:(id)anObject atIndexedSubscript:(NSUInteger)idx {

self.list[idx] = anObject;

}

– (id)objectAtIndexedSubscript:(NSUInteger)idx {

return self.list[idx];

}

@end

// Using the class

ItemCollection *items = [ItemCollection new];

items[1] = @”boo”;

This is a contrived example, but with some imagination, you could find some cool uses for this to make your code more concise. Not only is this available for arrays, but you can use the key-value methods used by NSDictionary as well – objectForKeyedSubscript: and setObjectForKeyedSubscript:

You can read more about this here: http://clang.llvm.org/docs/ObjectiveCLiterals.html