macOS/iOS API解説

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

目次

readFromData:options:documentAttributes:

データから属性付き文字列を作って返します
-(BOOL)readFromData:(NSData *)data options:(NSDictionary:
           options:(NSDictionary *)options:
           documentAttributes:(NSDictionary **)dict:

解説

データから属性付き文字列を作って返します。

返り値

( BOOL )

YES/NO

引数

( NSData * )data options:(NSDictionary
( NSDictionary * )options
( NSDictionary ** )dict

フレームワーク

ApplicationKit

クラス

NSMutableAttributedString Additions

Instance Methods

使用可能

10.3

参照

例文

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

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

                                                    
                          
maStr =[[NSMutableAttributedString alloc] initWithString:@"AttributedString\n" attributes:nil] ;
NSData *aData = [ NSData dataWithContentsOfFile : [opPanel filename] ] ;
        [maStr readFromData:aData options:nil documentAttributes:&dic];
[myOutlet insertText:maStr];
}
}