getInfoForFile:application:type:
パスで指定するファイルに関する情報を返します
- (BOOL)getInfoForFile:(NSString *)fullPath application:(NSString **)appName type:(NSString **)typefunc getInfoForFile(_ fullPath: String, application appName: AutoreleasingUnsafeMutablePointer<NSString?>, type type: AutoreleasingUnsafeMutablePointer<NSString?>) -> Bool
解説
パスで指定するファイルに関する情報を返します。
appNameにアプリケーション名がセットされます。
typeにファイルタイプがセットされます。
ファイルがなければNOを返します。
メソッド自体はエラーがなく実行できるが、値が帰ってこない。
ファイルタイプ自体が10.6で非推奨となっている。
もしかしたら使えないかもしれない。
返り値
取得できたかYES/NO
Objective-CBOOL
Bool
引数
フルパス
(NSString *)fullPathgetInfoForFile(_ fullPath: String
アプリケーション名を入れる
Objective-C(NSString **)appNameappName: AutoreleasingUnsafeMutablePointer<NSString?>
ファイルタイプを入れる
Objective-C(NSString **)typetype: AutoreleasingUnsafeMutablePointer<NSString?>
フレームワーク
ApplicationKit
クラス
NSWorkspace
使用可能
10.0
更新時のバージョン
OS X 10.10.3
Swift1.2
例文
#import "SetImage.h" @implementation SetImage - (IBAction)set:(id)sender { //開けるファイル拡張子の配列 NSArray *fileTypes = [ NSArray arrayWithObject : @"tiff" ]; //OpenPanelを作る NSOpenPanel *opPanel = [ NSOpenPanel openPanel ]; //OpenPanelの結果のボタン番号 int opRet; BOOL openResult; NSString *appName; NSString *fileType; //OpenPanelでファイル選択 opRet = [ opPanel runModalForDirectory : NSHomeDirectory() //どこのディレクトリを出すか file : @"Pictures" //どのファイルを選択しておくか types : fileTypes ];//選べるファイルタイプ if ( opRet == NSOKButton ) { // OPENPanelのボタンがOKなら openResult = [[NSWorkspace sharedWorkspace] getInfoForFile:[ opPanel filename ] application:&appName type:&fileType ]; NSLog(appName); NSLog(fileType); } } @end