macOS/iOS API解説

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

目次

RTFDFromRange:documentAttributes:

RTFDのデータ(NSDataオブジェクト)を返します
-(NSData *)RTFDFromRange:(NSRange)aRange:
          documentAttributes:(NSDictionary *)docAttributes:

解説

RTFDのデータ(NSDataオブジェクト)を返します。

返り値

( NSData * )

RTFDデータ

引数

( NSRange )aRange

範囲

( NSDictionary * )docAttributes

辞書属性

フレームワーク

ApplicationKit

クラス

NSAttributedStringAdditions

Instance Methods

使用可能

10.1

参照

- RTFFromRange:documentAttributes:
- RTFDFileWrapperFromRange:documentAttributes:

例文

#import "MyObject.h"

@implementation MyObject

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

    if ( opRet == NSOKButton ) {  // OPENPanelのボタンがOKなら
      aString = [[NSAttributedString allocWithZone:[self zone]] initWithPath:[opPanel filename] documentAttributes:NULL];
 
data = [aString RTFDFromRange:NSMakeRange(0,8) documentAttributes:nil];

}
}
@end