Monday, April 29, 2013

NSBundle executableURL example ios


Returns the file URL of the receiver's executable file.
- (NSURL *)executableURL
Return Value of [NSBundle executableURL]
The file URL of the receiving bundle’s executable file.
Example of [NSBundle executableURL]
// Get the bundle for the main application (not the subprocess).The executable lives in Contents/Helpers, so look two dirs up from its path for the main app bundle root.
NSArray *executablePathComponents = [[[NSBundle mainBundle] executableURL] pathComponents];
NSIndexSet *indexOfEveryComponentExceptLastTwo = [NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, [executablePathComponents count] - 2)];
NSBundle *myBundle = [NSBundle bundleWithURL:[NSURL fileURLWithPathComponents:[executablePathComponents objectsAtIndexes:indexOfEveryComponentExceptLastTwo]]];

// Load the controller nib.
NSNib *windowControllerNib = [[NSNib alloc] initWithNibNamed:@"MyWindowController" bundle:myBundle];
MyWindowController *windowController = [[MyWindowController alloc] init];
NSArray *topLevelObjects = nil;
[windowControllerNib instantiateNibWithOwner:windowController topLevelObjects:topLevelObjects];