Skip to content

Instantly share code, notes, and snippets.

@mattyohe
Last active December 12, 2015 10:19
Show Gist options
  • Save mattyohe/4758363 to your computer and use it in GitHub Desktop.
Save mattyohe/4758363 to your computer and use it in GitHub Desktop.
UIView Nib loading.
//
// UIView+NibLoading.h
//
// Created by Matt Yohe on 2/11/13.
//
#import <UIKit/UIKit.h>
@interface UIView (NibLoading)
+(instancetype)loadInstanceFromNib;
@end
//
// UIView+NibLoading.m
//
// Created by Matt Yohe on 2/11/13.
//
#import "UIView+NibLoading.h"
@implementation UIView (NibLoading)
+(instancetype)loadInstanceFromNib
{
UIView *result = nil;
NSArray *topLevelObjects = [[UINib nibWithNibName:NSStringFromClass([self class]) bundle:nil] instantiateWithOwner:nil options:nil];
for (id anObject in topLevelObjects)
{
if ([anObject isKindOfClass:[self class]])
{
result = anObject;
break;
}
}
return result;
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment