Coder Social home page Coder Social logo

aocudl's Introduction

#Alternative Objective-C User Defined Literals AOCUDL was inspired by Dustin Bachrach's OCUDL.

The purpose of AOCUDL is to provide a simple way to define custom literals for Objective-C. These are correctly typecast, extensible and flexible.

To add this to your project using CocoaPods just add the following to your podfile:

pod 'AOCUDL', '~> 1.0'

##Example

NSURLRequest *request = $(NSURLRequest)[@"http://hypercrypt.net"];
NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:request delegate:self];

or simply

NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:$(NSURLRequest)[@"http://hypercrypt.net"] delegate:self];

This functionality is provided by using Objective-C subscripting and a small macro to glue the whole thing together:

#define $(cls) (cls *)((id)[cls class])

For a custom class to support AOCUDL all that needs to be implemented is one (or both) of the following methods:

+ (instancetype)objectAtIndexedSubscript:(NSUInteger)index;
+ (instancetype)objectForKeyedSubscript:(id)key;

The default implementation on NSObject is to return nil.

##Useful Literals AOCUDL includes a few literals for built-in classes, they broadly match those included by OCUDL. Examples:

  • NSMutableURLRequest: $(NSMutableURLRequest)[@"http://hypercrypt.net"] - This creates a GET request
  • NSNull: $NSNull or $(NSNull)[any-id-or-NSUInteger]
  • NSSet: $(NSSet)[@[object1, object2, object3]]
  • NSURLRequest: $(NSURLRequest)[@"http://hypercrypt.net"] - This creates a GET request
  • NSURL: $(NSURL)[@"http://hypercrypt.net"]
  • NSUUID: $(NSUUID)[@"8DFD5DF3-6D8B-4DC4-B0A2-1F8ED614FC16"]
  • UIColor: $(UIColor)[0xff0000]
  • UIImage: $(UIImage)[@"testImage"]
  • UINib: $(UINib)[@"AOCUDLViewController"]
  • UIStoryboard: $(UIStoryboard)[@"Main_iPhone"]

aocudl's People

Contributors

hypercrypt avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.