Eliminating stringly-typed code in Objective-C

It’s not so hard to write a script that puts your strings in compiled code and lets you avoid a whole class of bugs. After all, asset catalogs are just nested folder structures with JSON metadata, and storyboards are a pretty readable dialect of XML.

objc-assetgen takes your asset catalogs and objc-identifierconstants takes your storyboards and outputs a couple of small source code files that turn this code:

UIImage *buttonImage = [UIImage imageNamed:@"GreenButton"];
UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:@"Cell with Switch" forIndexPath:indexPath];

into this code:

UIImage *buttonImage = [AppCatalog greenButtonImage];
UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:AppStoryboardCellWithSwitchIdentifier forIndexPath:indexPath];

Square Engineering Blog