Showing posts with label NSBundle bundleURL example. Show all posts
Showing posts with label NSBundle bundleURL example. Show all posts

Monday, April 29, 2013

NSBundle bundleURL example ios


bundleURL

Returns the full URL of the receiver’s bundle directory.
- (NSURL *)bundleURL
Return Value
The full URL of the receiver’s bundle directory.
Example of [NSBundle bundleURL]
- (void) loadBundleWithURL:(NSURL *)bundleURL{
    NSBundle *newBundle = [NSBundle bundleWithURL:bundleURL];
    if (newBundle){
        [self setBundle:newBundle];
        [self setPluginInstance:[[[[self.bundle principalClass] alloc] init] autorelease]];

        NSLog(@"New bundle: %@", self.bundle);
        NSLog(@"New bundle's principal class %@", [self.bundle principalClass]);
        NSLog(@"Principal class' bundle is %@", [NSBundle bundleForClass:[self.bundle principalClass]]);
        NSLog(@"Plugin's class %@", [self.pluginInstance class]);
    }
}
Example of [NSBundle bundleURL]
NSURL * bundle = [[NSBundle mainBundle] bundleURL];
NSURL * file = [NSURL URLWithString:@"../Data/file.txt" relativeToURL:bundle];
NSURL * absoluteFile = [file absoluteURL];