bundleWithPath:
指定したパスのバンドルオブジェクトを返します
+(NSBundle *)bundleWithPath:(NSString *)path:
解説
指定したパス(path)のバンドルオブジェクトを返します
指定したディレクトリーパスがなければ、nilを返します。
存在しないならば、このメソッドはオブジェクトを割り当てて、初期化して返します。
返り値
( NSBundle * )
バンドル
引数
( NSString * )path
パス
フレームワーク
Foundation
クラス
NSBundle
Class Methods
使用可能
10.0
iOS2.0
参照
+ mainBundle
+ bundleForClass:
例文
#pragma mark bundleWithPath: -(void)method004 { NSBundle *bundle = [NSBundle bundleWithPath: @"/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.1.sdk/System/Library/PrivateFrameworks/BluetoothManager.framework" ]; NSLog(@"%s : %@",__FUNCTION__ ,[bundle resourcePath]); //シミュレータでの結果 //=>-[OOOAppDelegate method004] : /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.1.sdk/System/Library/PrivateFrameworks/BluetoothManager.framework }
//開けるファイル拡張子の配列 NSArray *imgTypes = [ NSArray arrayWithObject : @"app" ]; //OpenPanelを作る NSOpenPanel *opPanel = [ NSOpenPanel openPanel ]; //OpenPanelの結果のボタン番号 int opRet; NSBundle *bundle; //OpenPanelでファイル選択 opRet = [ opPanel runModalForDirectory : NSHomeDirectory() //どこのディレクトリを出すか file : @"Pictures" //どのどのファイルを選択しておくか types : imgTypes ];//選べるファイルタイプ if ( opRet == NSOKButton ) { // OPENPanelのボタンがOKなら bundle = [ NSBundle bundleWithPath: [ opPanel filename ] ]; NSLog([bundle resourcePath]); NSLog([bundle bundlePath]); }