1 #import "ITCategory-NSBundle.h"
3 @implementation NSBundle (ITFoundationCategory)
5 + (NSBundle *)bundleForFrameworkWithIdentifier:(NSString *)frameworkIdentifier {
6 NSMutableArray *frameworksPaths = [NSMutableArray array];
7 NSArray *libraryPaths = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory,NSAllDomainsMask,YES);
8 NSEnumerator *libraryEnumerator = [libraryPaths objectEnumerator];
11 [frameworksPaths addObject:[[self mainBundle] privateFrameworksPath]];
12 [frameworksPaths addObject:[[self mainBundle] sharedFrameworksPath]];
14 while ((libraryPath = [libraryEnumerator nextObject])) {
15 [frameworksPaths addObject:[libraryPath stringByAppendingPathComponent:@"Frameworks"]];
16 [frameworksPaths addObject:[libraryPath stringByAppendingPathComponent:@"PrivateFrameworks"]];
19 NSEnumerator *frameworksEnumerator = [frameworksPaths objectEnumerator];
20 NSString *frameworksPath;
22 while ((frameworksPath = [frameworksEnumerator nextObject])) {
23 NSArray *frameworkPaths = [NSBundle pathsForResourcesOfType:@"framework" inDirectory:frameworksPath];
24 NSEnumerator *frameworkEnumerator = [frameworkPaths objectEnumerator];
25 NSString *frameworkPath;
27 while ((frameworkPath = [frameworkEnumerator nextObject])) {
28 NSBundle *frameworkBundle = [NSBundle bundleWithPath:frameworkPath];
29 if (frameworkBundle && [[frameworkBundle bundleIdentifier] isEqualToString:frameworkIdentifier]) {
30 return frameworkBundle;