macOS/iOS API解説

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

目次

initWithRTFD:documentAttributes:

RTFDデータから属性付き文字列を作って初期化して返します
-(id)initWithRTFD:(NSData *)rtfdData:
           documentAttributes:(NSDictionary **)docAttributes:

解説

RTFDデータから属性付き文字列を作って初期化して返します。
文書属性を辞書で返します。
データを読むことができなければnilを返します。

返り値

( id )

文字列

引数

( NSData * )rtfdData

RTFDデータ

( NSDictionary ** )docAttributes

文書属性のポインタ

フレームワーク

ApplicationKit

クラス

NSAttributedStringAdditions

Instance Methods

使用可能

10.1

参照

例文

#import "MyObject.h"

@implementation MyObject

- (IBAction)myAction:(id)sender
{//開けるファイル拡張子の配列
    NSArray      *fileTypes    = [ NSArray arrayWithObject : @"rtfd" ];
    //OpenPanelを作る
    NSOpenPanel  *opPanel       = [ NSOpenPanel openPanel ];
    
    NSAttributedString *aString;
    
    NSData *rtfdData;
    //OpenPanelの結果のボタン番号
    int		  opRet;
     
        //OpenPanelでファイル選択   
    opRet = [ opPanel runModalForDirectory : NSHomeDirectory() //どこのディレクトリを出すか
                                     file : @"Documents" //どのファイルを選択しておくか
                                    types : fileTypes ];//選べるファイルタイプ

    if ( opRet == NSOKButton ) {  // OPENPanelのボタンがOKなら
        rtfdData = [NSData dataWithContentsOfFile:[opPanel filename]];
    
    aString = [[NSAttributedString allocWithZone:[self zone]] initWithRTFD:rtfdData documentAttributes:NULL];
    
}
}
@end