Skip to content

Instantly share code, notes, and snippets.

@NSExceptional
Created July 29, 2016 22:52
Show Gist options
  • Save NSExceptional/d3429048c4f50cfe334ea02d63f96e9f to your computer and use it in GitHub Desktop.
Save NSExceptional/d3429048c4f50cfe334ea02d63f96e9f to your computer and use it in GitHub Desktop.
Macro to make a static NSArray within a function or method
#define StaticNSArray(name, ...) nil; static dispatch_once_t ___onceToken; dispatch_once(&___onceToken, ^{ name = @[__VA_ARGS__]; })
- (void)foo {
...
static NSArray *animals = StaticNSArray(typeQualifiers, @"cat", @"dog", @"bunny");
...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment