Skip to content

Instantly share code, notes, and snippets.

@briancroom
Last active August 29, 2015 14:25
Show Gist options
  • Save briancroom/b135c6ea98383b45bd56 to your computer and use it in GitHub Desktop.
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.
#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