Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
An example of how loading a nib file with a custom view can be done
// UIView+KHMNibLoading.h
@interface UIView (KHMNibLoading)
+ (instancetype)viewFromNib;
@end
// UIView+KHMNibLoading.m
+ (instancetype)viewFromNib {
NSString *className = NSStringFromClass([self class]);
NSArray *bundle = [[NSBundle mainBundle] loadNibNamed:className owner:self options:nil];
id view = nil;
for (id object in bundle) {
if ([object isKindOfClass:[self class]]) {
view = object;
}
}
NSAssert(view != nil, @"Failed attempt to load %@ from nib", className);
return view;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.