Huge update to ITFoundation. I've gone through every file (except queue.h
[ITFoundation.git] / ITCategory-NSBundle.m
1 #import "ITCategory-NSBundle.h"
2
3 @implementation NSBundle (ITFoundationCategory)
4
5 + (NSBundle *)bundleForFrameworkWithIdentifier:(NSString *)frameworkIdentifier {
6         NSMutableArray *frameworksPaths = [NSMutableArray array];
7         NSArray *libraryPaths = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory,NSAllDomainsMask,YES);
8         NSEnumerator *libraryEnumerator = [libraryPaths objectEnumerator];
9         NSString *libraryPath;
10         
11         [frameworksPaths addObject:[[self mainBundle] privateFrameworksPath]];
12         [frameworksPaths addObject:[[self mainBundle] sharedFrameworksPath]];
13         
14         while (libraryPath = [libraryEnumerator nextObject]) {
15                 [frameworksPaths addObject:[libraryPath stringByAppendingPathComponent:@"Frameworks"]];
16                 [frameworksPaths addObject:[libraryPath stringByAppendingPathComponent:@"PrivateFrameworks"]];
17         }
18         
19         NSEnumerator *frameworksEnumerator = [frameworksPaths objectEnumerator];
20         NSString *frameworksPath;
21         
22         while (frameworksPath = [frameworksEnumerator nextObject]) {
23                 NSArray *frameworkPaths = [NSBundle pathsForResourcesOfType:@"framework" inDirectory:frameworksPath];
24                 NSEnumerator *frameworkEnumerator = [frameworkPaths objectEnumerator];
25                 NSString *frameworkPath;
26                 
27                 while (frameworkPath = [frameworkEnumerator nextObject]) {
28                         NSBundle *frameworkBundle = [NSBundle bundleWithPath:frameworkPath];
29                         if (frameworkBundle && [[frameworkBundle bundleIdentifier] isEqualToString:frameworkIdentifier]) {
30                                 return frameworkBundle;
31                         }
32                 }
33         }
34         
35         return nil;
36 }
37
38 @end