Created
July 11, 2012 10:37
-
-
Save danielctull/3089554 to your computer and use it in GitHub Desktop.
NSBundle category to recursively look through directories and find a bundle with the given name
This file contains hidden or 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
| // | |
| // NSBundle+DCTBundleWithName.h | |
| // | |
| // Created by Daniel Tull on 11/07/2012. | |
| // Copyright (c) 2012 Daniel Tull. All rights reserved. | |
| // | |
| #import <Foundation/Foundation.h> | |
| @interface NSBundle (DCTBundleWithName) | |
| + (NSBundle *)dct_bundleWithName:(NSString *)name; | |
| @end |
This file contains hidden or 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
| // | |
| // NSBundle+DCTBundleWithName.m | |
| // | |
| // Created by Daniel Tull on 11/07/2012. | |
| // Copyright (c) 2012 Daniel Tull. All rights reserved. | |
| // | |
| #import "NSBundle+DCTBundleWithName.h" | |
| @implementation NSBundle (DCTBundleWithName) | |
| + (NSBundle *)dct_bundleWithName:(NSString *)name { | |
| if (![name hasSuffix:@".bundle"]) | |
| name = [NSString stringWithFormat:@"%@.bundle", name]; | |
| NSDirectoryEnumerator *enumerator = [[NSFileManager new] enumeratorAtURL:[[NSBundle mainBundle] bundleURL] | |
| includingPropertiesForKeys:nil | |
| options:NSDirectoryEnumerationSkipsHiddenFiles | |
| errorHandler:NULL]; | |
| for (NSURL *URL in enumerator) | |
| if ([[URL lastPathComponent] isEqualToString:name]) | |
| return [NSBundle bundleWithURL:URL]; | |
| return nil; | |
| } | |
| @end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment