Skip to content

Instantly share code, notes, and snippets.

@mimay
Forked from jamztang/LICENSE
Created August 19, 2013 07:29
Show Gist options
  • Select an option

  • Save mimay/6266502 to your computer and use it in GitHub Desktop.

Select an option

Save mimay/6266502 to your computer and use it in GitHub Desktop.
//
// NSObject+JTNibLoader.h
//
// Created by james on 8/22/11.
//
#import <Foundation/Foundation.h>
@interface NSObject (JTNibLoader)
+ (id)objectWithNibNamed:(NSString *)nibName;
@end
//
// NSObject+JTNibLoader.m
//
// Created by james on 8/22/11.
//
#import "NSObject+JTNibLoader.h"
@implementation NSObject (JTNibLoader)
+ (id)objectWithNibNamed:(NSString *)nibName {
NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:nibName owner:nil options:nil];
for(id currentObject in topLevelObjects)
{
if([currentObject isKindOfClass:[self class]])
{
return currentObject;
break;
}
}
return nil;
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment