initWithContentsOfFile:
ファイルの中身で配列を初期化して返します
-(id)initWithContentsOfFile:(NSString *)aPath
解説
ファイルの中身で配列を初期化して返します。
ファイルはwriteToFile:atomically: で書き出された配列のファイルでないといけません。
配列にはNSString、NSData、NSArray、NSDictionaryだけを含まないといけません。
ファイルの内容を解析できなかったり、ファイルを開くことが出来なければnilを返します。
返り値
( id )
配列(NSArrayまたはそのサブクラス)
引数
( NSString * )aPath
内容を読むファイルパス
フレームワーク
Foundation
クラス
NSArray
Instance Methods
使用可能
10.0
iOS2.0
参照
+ arrayWithContentsOfFile:
- writeToFile:atomically:
例文
#pragma mark initWithContentsOfFile: -(void)method031 { NSString *resourcePath = [[NSBundle mainBundle] pathForResource:@"plistfile" ofType:@"plist"]; NSArray *anArray = [[NSArray alloc] initWithContentsOfFile:resourcePath]; NSLog(@"%s = %@",__FUNCTION__,[anArray description]); //バンドル内のplistfile.plistファイルからNSArrayがつくられる。 //ファイルがないと例外が投げられます。 //=>(aaa,2,bbb,ccc) }