Created
January 8, 2015 04:07
-
-
Save nevyn/baebeadd238388f9000d to your computer and use it in GitHub Desktop.
This is how I use open source libraries like SPAsync, FormatterKit, SWTableViewCell and others within the Lookback SDK, without getting linking conflicts within apps that use the same libraries.
This file contains 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
// http://rentzsch.tumblr.com/post/40806448108/ns-poor-mans-namespacing-for-objective-c | |
// This namespacing method is used to namespace libraries used by Lookback, so | |
// that apps incorporating the SDK can have the same class in it without clashing. | |
// (ugh, give me swift nooow). | |
#ifndef GFNAMESPACE | |
// Default to using the 'GF' prefix | |
#define GFNAMESPACE GF | |
#endif | |
#define GFNSxstr(s) GFNSstr(s) | |
#define GFNSstr(s) #s | |
#define GFNAMESPACESTR GFNSxstr(GFNAMESPACE) | |
#define GFNS_CONCAT_TOKENS(a,b) a##b | |
#define GFNS_EVALUATE(a,b) GFNS_CONCAT_TOKENS(a,b) | |
#define NS(original_name) GFNS_EVALUATE(GFNAMESPACE, original_name) | |
// Usage: define GFNAMESPACE as a build setting in your library. | |
// Then, define classes like this: | |
@interface NS(NetworkClient) : NSObject | |
@end | |
// This will become GFNetworkClient if you don't define the constant, or | |
// ABCDNetworkClient inside your ABCD library. Use it like this: | |
NS(NetworkClient) *myClient = [[NS(NetworkClient) alloc] initWithStuff:hey]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment