Skip to content

Instantly share code, notes, and snippets.

@yourtion
Created November 8, 2016 14:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yourtion/7075c5eb1a1b1a248a05588ff677808d to your computer and use it in GitHub Desktop.
Save yourtion/7075c5eb1a1b1a248a05588ff677808d to your computer and use it in GitHub Desktop.
about frame bundle
#import <UIKit/UIKit.h>
@interface MyViewController : UIViewController
@end
@implementation MyViewController
- (id)init {
NSBundle *bundle = [NSBundle bundleWithURL:[[NSBundle mainBundle] URLForResource:@"MyLibraryResources" withExtension:@"bundle"]];
if ((self = [super initWithNibName:@"MyViewController" bundle:bundle])) {
}
return self;
}
@end
@interface NSBundle (MyLibrary)
+ (NSBundle*)myLibraryResourcesBundle;
@end
@implementation NSBundle (MyLibrary)
+ (NSBundle*)myLibraryResourcesBundle {
static dispatch_once_t onceToken;
static NSBundle *myLibraryResourcesBundle = nil;
dispatch_once(&onceToken, ^{
myLibraryResourcesBundle = [NSBundle bundleWithURL:[[NSBundle mainBundle] URLForResource:@"MyLibraryResources" withExtension:@"bundle"]];
});
return myLibraryResourcesBundle;
}
@end
@implementation UIImage (MyLibrary)
+ (UIImage*)myLibraryImageNamed:(NSString*)name;
@end
@implementation UIImage (MyLibrary)
+ (UIImage*)myLibraryImageNamed:(NSString*)name {
UIImage *imageFromMainBundle = [UIImage imageNamed:name];
if (imageFromMainBundle) {
return imageFromMainBundle;
}
UIImage *imageFromMyLibraryBundle = [UIImage imageWithContentsOfFile:[[[NSBundle myLibraryResourcesBundle] resourcePath] stringByAppendingPathComponent:name]];
return imageFromMyLibraryBundle;
}
@end
// http://www.galloway.me.uk/tutorials/ios-library-with-resources/
@interface NSBundle (YourFrameworkBundle)
+ (NSBundle *)yourFrameworkBundle;
@end
#import "NSBundle+YourFrameworkBundle.h"
@implementation NSBundle (YourFrameworkBundle)
+ (NSBundle *)yourFrameworkBundle
{
static NSBundle *frameworkBundle = nil;
static dispatch_once_t predicate;
dispatch_once(&predicate, ^{
NSString *mainBundlePath = [[NSBundle mainBundle] resourcePath];
frameworkBundle = [NSBundle bundleWithPath:[mainBundlePath stringByAppendingPathComponent:@"YourFrameworkBundle.bundle"]];
});
return frameworkBundle;
}
@end
// http://stackoverflow.com/questions/35067172/how-can-i-include-my-resource-files-in-my-framework-without-using-a-separate-bun
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment