Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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.
#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
// 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