macOS/iOS API解説

iOS , Mac アプリケーション開発のために使われる主要フレームワークの日本語情報です。2010年代に書かれた内容です。今後更新はありません。

目次

initWithPath:

ディレクトリのNSBundleを返します
-(id)initWithPath:(NSString *)fullPath:

解説

ディレクトリ(fullPath)のNSBundleを返します。
既存のオブジェクトがある場合はそれを返して、無い場合はつくって初期化して返します。
fullPathは絶対パスで、エイリアスシンボリックリンク)でもよいです。
ディレクトリが存在しない、ユーザーがそれにアクセスをできないなら、nilを返します。

mainBundleやbundleWithPathを使うこともできます。

指定のイニシャライザです。

返り値

( id )

バンドル

引数

( NSString * )fullPath

フルパス

クラス

NSBundle

Instance Methods

使用可能

10.0
iOS2.0

参照

+ bundleForClass:

例文

//開けるファイル拡張子の配列
    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 alloc ] 
                          initWithPath: [ opPanel filename ] ];
NSLog([bundle resourcePath]);
    }