Last active
August 29, 2015 14:25
-
-
Save briancroom/b135c6ea98383b45bd56 to your computer and use it in GitHub Desktop.
If you want to begin taking advantage of Xcode 7's generics for Objective-C but need to maintain backwards compatibility, try using something like this.
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
#if __has_feature(objc_generics) | |
#define BC_GENERIC(GENERIC_TYPE) <GENERIC_TYPE> | |
#define BC_GENERIC_TYPE(GENERIC_TYPE) GENERIC_TYPE | |
#else | |
#define BC_GENERIC(GENERIC_TYPE) | |
#define BC_GENERIC_TYPE(GENERIC_TYPE) id | |
#endif |
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
// For variable declaration | |
NSArray BC_GENERIC(NSString *) *stringArray = @[@"Hi", @"There"]; | |
// For a custom class utilizing generics | |
@interface MyGenericClass BC_GENERIC(ObjectType) : NSObject | |
- (void)doSomethingWithAnObject:(BC_GENERIC_TYPE(ObjectType))object; | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment