initWithContentsOfFile:ofType:
ファイルからドキュメントオブジェクトを初期化して返します
-(id)initWithContentsOfFile:(NSString *)fileName: ofType:(NSString *)docType:
解説
ファイルからドキュメントオブジェクト(NSDocument)を初期化して返します。
返り値
( id )
NSDocumentオブジェクト
引数
( NSString * )fileName
ファイル名
( NSString * )docType
文書タイプ
フレームワーク
ApplicationKit
クラス
NSDocument
Instance Methods
使用可能
10.0
参照
例文
#import "MyObject.h" #import "MyDocument.h" @implementation MyObject - (IBAction)myAction:(id)sender { //開けるファイル拡張子の配列 NSArray *fileTypes = [ NSArray arrayWithObjects : @"txt",@"'TEXT'",nil ]; //OpenPanelを作る NSOpenPanel *opPanel = [ NSOpenPanel openPanel ]; // MyDocument *doc; //OpenPanelの結果のボタン番号 int opRet; //OpenPanelでファイル選択 opRet = [ opPanel runModalForDirectory : NSHomeDirectory() //どこのディレクトリを出すか file : @"Documents" //どのファイルを選択しておくか types : fileTypes ];//選べるファイルタイプ if ( opRet == NSOKButton ) { // OPENPanelのボタンがOKなら //ファイルから読み込む doc = [[MyDocument alloc] initWithContentsOfFile:[opPanel filename] ofType:@"txt"]; } } @end