Skip to content

Instantly share code, notes, and snippets.

@Tricertops
Tricertops / NSLiterals.m
Created May 24, 2017 06:53
Macros for creating NSArray and NSSet objects as replacement for @[…] literal.
// Macros for creating NSArray and NSSet objects as replacement for @[…] literal.
let components = NSArray(street, city, state, country);
// Advantages:
// 1. Type of NSArray is inferred, in this case it’s NSArray<NSString *> *
// 2. List of objects is type-checked, so mixing types like NSArray(@42, @"Hi") will report compilation error.
// 3. Ability to allocate any class, not just NSArray. For example NSSet and NSMutableArray.
// 4. Avoids stupid clang bracket matching bug, if you know what I mean.