X-Git-Url: http://git.ithinksw.org/ITFoundation.git/blobdiff_plain/20a493a9e6456c60066b2d1d60fdb321427d9ca8..3215be951cbc1e5e8bad14701507b68ebf380ab5:/ITCategory-NSBundle.m diff --git a/ITCategory-NSBundle.m b/ITCategory-NSBundle.m new file mode 100644 index 0000000..c7acbcc --- /dev/null +++ b/ITCategory-NSBundle.m @@ -0,0 +1,38 @@ +#import "ITCategory-NSBundle.h" + +@implementation NSBundle (ITCategory) + ++ (NSBundle *)bundleForFrameworkWithIdentifier:(NSString *)frameworkIdentifier { + NSMutableArray *frameworksPaths = [NSMutableArray array]; + NSArray *libraryPaths = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory,NSAllDomainsMask,YES); + NSEnumerator *libraryEnumerator = [libraryPaths objectEnumerator]; + NSString *libraryPath; + + [frameworksPaths addObject:[[self mainBundle] privateFrameworksPath]]; + [frameworksPaths addObject:[[self mainBundle] sharedFrameworksPath]]; + + while (libraryPath = [libraryEnumerator nextObject]) { + [frameworksPaths addObject:[libraryPath stringByAppendingPathComponent:@"Frameworks"]]; + [frameworksPaths addObject:[libraryPath stringByAppendingPathComponent:@"PrivateFrameworks"]]; + } + + NSEnumerator *frameworksEnumerator = [frameworksPaths objectEnumerator]; + NSString *frameworksPath; + + while (frameworksPath = [frameworksEnumerator nextObject]) { + NSArray *frameworkPaths = [NSBundle pathsForResourcesOfType:@"framework" inDirectory:frameworksPath]; + NSEnumerator *frameworkEnumerator = [frameworkPaths objectEnumerator]; + NSString *frameworkPath; + + while (frameworkPath = [frameworkEnumerator nextObject]) { + NSBundle *frameworkBundle = [NSBundle bundleWithPath:frameworkPath]; + if (frameworkBundle && [[frameworkBundle bundleIdentifier] isEqualToString:frameworkIdentifier]) { + return frameworkBundle; + } + } + } + + return nil; +} + +@end