Skip to content

Instantly share code, notes, and snippets.

@xhacker
Created September 6, 2015 14:49
Show Gist options
  • Save xhacker/b6cb29719333d80360fc to your computer and use it in GitHub Desktop.
Save xhacker/b6cb29719333d80360fc to your computer and use it in GitHub Desktop.
appearanceWhenContainedIn: for Swift
#import "UIAppearance+Swift.h"
@implementation UIView (UIViewAppearance_Swift)
+ (instancetype)swift_appearanceWhenContainedIn:(NSArray *)containerClasses
{
NSUInteger count = containerClasses.count;
NSAssert(count <= 10, @"The count of containers greater than 10 is not supported.");
return [self appearanceWhenContainedIn:
count > 0 ? containerClasses[0] : nil,
count > 1 ? containerClasses[1] : nil,
count > 2 ? containerClasses[2] : nil,
count > 3 ? containerClasses[3] : nil,
count > 4 ? containerClasses[4] : nil,
count > 5 ? containerClasses[5] : nil,
count > 6 ? containerClasses[6] : nil,
count > 7 ? containerClasses[7] : nil,
count > 8 ? containerClasses[8] : nil,
count > 9 ? containerClasses[9] : nil,
nil];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment