unarchiveObjectWithFile:
ファイルパスでアーカイブされるオブジェクトを解読して返します
+(id)unarchiveObjectWithFile:(NSString *)path:
解説
ファイルパスでアーカイブされるオブジェクトを解読して返します。
返り値
( id )
オブジェクト
引数
( NSString * )path
ファイルパス
フレームワーク
Foundation
クラス
NSUnarchiver
Class Methods
使用可能
10.0
参照
例文
#import "MyObject.h" #import "MyView.h" @implementation MyObject - (IBAction)slider:(id)sender { } - (IBAction)archive:(id)sender { //セーブパネル設定 NSSavePanel *savePanel = [NSSavePanel savePanel]; //拡張子codeにする [savePanel setRequiredFileType:@"code"]; //ウインドウのコンテンツビュー丸ごとアーカイブ switch ([savePanel runModalForDirectory:NSHomeDirectory() file:@""]) { case NSOKButton: [NSArchiver archiveRootObject:[window contentView] toFile:[savePanel filename]]; break; } } - (IBAction)unarchive:(id)sender { //拡張子codeのファイルを選ぶ NSArray *fileTypes = [NSArray arrayWithObject:@"code"]; //オープンパネル設定 NSOpenPanel *openPanel = [NSOpenPanel openPanel]; //ホームディレクトリで開く [openPanel setDirectory:NSHomeDirectory()]; // if ([openPanel runModalForTypes:fileTypes]) { id aView = [NSUnarchiver unarchiveObjectWithFile: [openPanel filename]]; [(NSWindow *)window setContentView:aView]; } } @end