From 3215be951cbc1e5e8bad14701507b68ebf380ab5 Mon Sep 17 00:00:00 2001 From: Joseph Spiros Date: Wed, 16 Feb 2005 04:27:11 +0000 Subject: [PATCH] ITCategory-NSBundle (new): Added category that adds +bundleForFrameworkWithIdentifier: class method to NSBundle. --- ITCategory-NSBundle.h | 18 ++++++++++++++ ITCategory-NSBundle.m | 38 ++++++++++++++++++++++++++++++ ITFoundation.xcode/project.pbxproj | 32 +++++++++++++++++++++++++ 3 files changed, 88 insertions(+) create mode 100644 ITCategory-NSBundle.h create mode 100644 ITCategory-NSBundle.m diff --git a/ITCategory-NSBundle.h b/ITCategory-NSBundle.h new file mode 100644 index 0000000..7211858 --- /dev/null +++ b/ITCategory-NSBundle.h @@ -0,0 +1,18 @@ +/* + * ITFoundation + * ITCategory-NSBundle.h + * + * Copyright (c) 2005 by iThink Software. + * All Rights Reserved. + * + * $Id$ + * + */ + +#import + +@interface NSBundle (ITCategory) + ++ (NSBundle *)bundleForFrameworkWithIdentifier:(NSString *)frameworkIdentifier; + +@end 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 diff --git a/ITFoundation.xcode/project.pbxproj b/ITFoundation.xcode/project.pbxproj index e7e51ca..f32054d 100755 --- a/ITFoundation.xcode/project.pbxproj +++ b/ITFoundation.xcode/project.pbxproj @@ -210,6 +210,8 @@ //2A4 2AB93A2C057059DC007E748F = { children = ( + 7C2D93BD07C2FD6700A487A9, + 7C2D93BE07C2FD6700A487A9, 7C058DF7072F10530082E1E9, 7C058DF8072F10530082E1E9, 2AB93A3005705A0C007E748F, @@ -628,6 +630,34 @@ settings = { }; }; + 7C2D93BD07C2FD6700A487A9 = { + fileEncoding = 4; + isa = PBXFileReference; + lastKnownFileType = sourcecode.c.h; + path = "ITCategory-NSBundle.h"; + refType = 4; + sourceTree = ""; + }; + 7C2D93BE07C2FD6700A487A9 = { + fileEncoding = 4; + isa = PBXFileReference; + lastKnownFileType = sourcecode.c.objc; + path = "ITCategory-NSBundle.m"; + refType = 4; + sourceTree = ""; + }; + 7C2D93BF07C2FD6700A487A9 = { + fileRef = 7C2D93BD07C2FD6700A487A9; + isa = PBXBuildFile; + settings = { + }; + }; + 7C2D93C007C2FD6700A487A9 = { + fileRef = 7C2D93BE07C2FD6700A487A9; + isa = PBXBuildFile; + settings = { + }; + }; 7C97DC2C05B614300013E85F = { fileEncoding = 4; isa = PBXFileReference; @@ -910,6 +940,7 @@ 3D97138A05D9FD6B0033607F, 376AF4DF06597CA900F0979E, 7C058DF9072F10530082E1E9, + 7C2D93BF07C2FD6700A487A9, ); isa = PBXHeadersBuildPhase; runOnlyForDeploymentPostprocessing = 0; @@ -949,6 +980,7 @@ 3D97138B05D9FD6B0033607F, 376AF4E006597CA900F0979E, 7C058DFA072F10530082E1E9, + 7C2D93C007C2FD6700A487A9, ); isa = PBXSourcesBuildPhase; runOnlyForDeploymentPostprocessing = 0; -- 2.20.1