Created
November 8, 2016 14:15
-
-
Save yourtion/7075c5eb1a1b1a248a05588ff677808d to your computer and use it in GitHub Desktop.
about frame bundle
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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