macOS/iOS API解説

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

目次

fileWrapperRepresentationOfType:

指定したタイプでレシーバのデータを表すNSFileWrapperオブジェクトを返します
-(NSFileWrapper *)fileWrapperRepresentationOfType:(NSString *)aType:

解説

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

返り値

( NSFileWrapper * )

ファイルラッパー

引数

( NSString * )aType

タイプ

フレームワーク

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;
    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