macOS/iOS API解説

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

目次

pathForResource:ofType:inDirectory:

バンドルのリソースから名前と拡張子でファイルを探してそのパスを返します
-(NSString *)pathForResource:(NSString *)name:
             ofType:(NSString *)extension:
             inDirectory:(NSString *)bundlePath:

解説

名前で指定したリソースのための、指定したファイル名拡張子とbundlePathなディレクトリに属するフルパス名を返します。
バンドルに合うリソースがなければnilを返します。

● <メインバンドルパス>/Resources/bundlePath/name.extension
● <メインバンドルパス>/Resources/bundlePath//name.extension
● <メインバンドルパス>/bundlePath/name.extension
● <メインバンドルパス>/bundlePath//name.extension

検索言語ディレクトリ、ユーザーの初期設定で設定されたもの
bundlePathがnilなら、bundlePathなしで、同じサーチ順序になります。

返り値

( NSString * )

パス

引数

( NSString * )name

ファイル名

( NSString * )extension

拡張子

( NSString * )bundlePath

バンドルパ

クラス

NSBundle

Instance Methods

使用可能

10.0
iOS2.0

参照

- localizedStringForKey:value:table:
- pathForResource:ofType:
- pathsForResourcesOfType:inDirectory:
+ pathForResource:ofType:inDirectory:
+ pathsForResourcesOfType:inDirectory:

例文

#import "SetImage.h"

@implementation SetImage

- (IBAction)set:(id)sender
{
//
    NSString *string;

        string = [[NSBundle mainBundle]  pathForResource:@"Japanese" ofType:@"lproj" inDirectory:@"newFolder"];


    if (string!=nil){
 [str setStringValue:string];
    }else{
     [str setStringValue:@"Nil"];
       
    }
}

@end