Nifty Library Allowing You To Define Your Own Objective-C Literals

With iOS 6, and Xcode 4.4 a number of Objective-C literals were added reducing the code needed to define an NSArray, NSDictionary or NSNumber.

Here’s a library that allows you to add user defined literals to Objective-C called OCUDL from Dustin Bachrach.

You can create literals both by applying an implementing the included protocol, or on a specific block of code so you can turn just about anything into a literal.

There are also a number of defined literals included for UIImage, UIColor, UIStoryboard and more.

As Justin explains on his site you can turn some code such as:

UIColor *myColor = [UIColor colorWithRed:255.0f
                                    blue:(241.0f / 2555.0f)
                                   green:(35.0f / 255.0f)
                                   alpha:1.0f];

Into:

UIColor *myColor = $(#FFF123);

You can read more about OCUDL on Dustin’s blog.

You can find OCUDL on Github here.

A very nice addition to Objective-C.

FacebookTwitterDiggStumbleUponGoogle Plus

Original article: Nifty Library Allowing You To Define Your Own Objective-C Literals

©2013 iOS App Dev Libraries, Controls, Tutorials, Examples and Tools. All Rights Reserved.

Leave a Reply

Your email address will not be published. Required fields are marked *