Skip to content

Instantly share code, notes, and snippets.

@danielctull
Created July 11, 2012 10:37
Show Gist options
  • Select an option

  • Save danielctull/3089554 to your computer and use it in GitHub Desktop.

Select an option

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
//
// 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
//
// 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