Created
July 29, 2016 22:52
-
-
Save NSExceptional/d3429048c4f50cfe334ea02d63f96e9f to your computer and use it in GitHub Desktop.
Macro to make a static NSArray within a function or method
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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