NSDocument:fileWrapperRepresentationOfType:
Home 目次>ApplicationKit>NSDocument

fileWrapperRepresentationOfType:

指定したタイプでレシーバのデータを表すNSFileWrapperオブジェクトを返します


-(NSFileWrapper *) fileWrapperRepresentationOfType:(NSString *)aType


【返り値】
   NSFileWrapper *ファイルラッパー
【パラメータ】
   aTypeタイプ


【解説】

指定したタイプでレシーバのデータを表すNSFileWrapperオブジェクトを返します。
dataRepresentationOfTypeを呼び出す。



【例文】


#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;
NSURL *theUrl;
NSFileWrapper *fWrap;
//OpenPanel の結果のボタン番号
int opRet;

//OpenPanel でファイル選択
opRet = [ opPanel runModalForDirectory : NSHomeDirectory()
// どこのディレクトリを出すか
file :
@"Documents" // どのファイルを選択しておくか
types : fileTypes ];
// 選べるファイルタイプ

if ( opRet == NSOKButton ) { // OPENPanel のボタンが OK なら
// ファイルから読み込む

theUrl = [NSURL fileURLWithPath:[ opPanel filename ]];
doc = [[MyDocument alloc] initWithContentsOfURL:theUrl ofType:
@"txt" ];


fWrap = [doc fileWrapperRepresentationOfType:
@"txt" ];

NSLog([NSString stringWithFormat:
@"fileWrapper %@" ,[fWrap description]]);
NSLog([NSString stringWithFormat:
@"doc %@" ,[doc description]]);
NSLog([NSString stringWithFormat:
@"theUrl %@" ,[theUrl description]]);
}

}

@end


(C) 2000-2007 Satoshi Oomori.
[Apple]

Google
Webwww.oomori.com
Apple_Store_40x120

[ad:Usual day in Japan]

この記事を評価してください。 

良い 

間違いがある 説明がわかりにくい 例文がわかりにくい  

Home 目次>ApplicationKit>NSDocument
修正日2006.12.26