Skip to content

Instantly share code, notes, and snippets.

@Phillipus
Last active March 13, 2017 09:18
Show Gist options
  • Save Phillipus/6279347 to your computer and use it in GitHub Desktop.
Save Phillipus/6279347 to your computer and use it in GitHub Desktop.
Class Cluster example as described here - http://www.noxeos.com/2013/06/18/strategies-support-ios7-ui/
@interface MyView : UIView
- (void)kissMyAss;
@end
@interface _MyViewIOS6 : MyView
@end
@interface _MyViewIOS7 : MyView
@end
@implementation MyView
BOOL isIOS7 = YES; // This would be a function somewhere
+ (id)alloc {
if([self class] == [MyView class]) {
if(isIOS7) {
return [_MyViewIOS7 alloc];
}
else {
return [_MyViewIOS6 alloc];
}
}
return [super alloc];
}
- (void)kissMyAss {}
// Test method
+ (void)testClassCluster {
MyView *myView = [[MyView alloc] init];
[myView kissMyAss];
}
@end
@implementation _MyViewIOS6
- (void)kissMyAss {
NSLog(@"iOS 6 can kiss my ass");
}
@end
@implementation _MyViewIOS7
- (void)kissMyAss {
NSLog(@"iOS 7 can kiss my ass");
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment