macOS/iOS API解説

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

目次

readFromURL:options:documentAttributes:

URLから内容をセットします
-(BOOL)readFromURL:(NSURL *)url:
          options:(NSDictionary *)options:
          documentAttributes:(NSDictionary **)documentAttributes:

解説

URLから内容をセットします。
【オプション】
● @"CharacterEncoding"
● @"BaseURL"
● @"DefaultAttributes"

返り値

( BOOL )

YES/NO

引数

( NSURL * )url

URL

( NSDictionary * )options
( NSDictionary ** )documentAttributes

フレームワーク

ApplicationKit

クラス

NSMutableAttributedString Additions

Instance Methods

使用可能

10.0

参照

例文

#import "MyObject.h"

@implementation MyObject


- (IBAction)myAction:(id)sender
{
//開けるファイル拡張子の配列
    NSArray      *fileTypes    = [ NSArray arrayWithObject : @"txt" ];
    //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] ;

        [maStr readFromURL:[NSURL fileURLWithPath:[opPanel filename]]
 options:nil documentAttributes:&dic];
[myOutlet insertText:maStr];
}
}

- (IBAction)fix:(id)sender
{


}
@end