-initWithContentsOfURL:
anURLの内容で配列を作って返します
-(id)initWithContentsOfURL:(NSURL*)aURL
解説
URLの中身で配列を作って返します。
URLはwriteToURL:atomically: で書き出された配列のファイルでないといけません。
配列にはNSString、NSData、NSArray、NSDictionaryだけを含まないといけません。
ファイルの内容を解析できなかったり、ファイルを開くことが出来なければnilを返します。
返り値
( id )
配列(NSArrayまたはそのサブクラス)
引数
( NSURL* )aURL
NSURLオブジェクト
フレームワーク
Foundation
クラス
NSArray
Instance Methods
使用可能
10.0
iOS2.0
例文
#pragma mark initWithContentsOfURL: -(void)method030 { NSString *resourcePath = [[NSBundle mainBundle] pathForResource:@"plistfile" ofType:@"plist"]; NSURL *url = [NSURL fileURLWithPath:resourcePath]; NSArray *anArray = [[NSArray alloc] initWithContentsOfURL:url]; NSLog(@"%s = %@",__FUNCTION__,[anArray description]); //バンドル内のplistfile.plistファイルからNSArrayがつくられる。 //=>(aaa,2,bbb,ccc) // NSMutableArray *muArray = [[NSMutableArray alloc] initWithContentsOfURL:url]; NSLog(@"%s = %@",__FUNCTION__,[muArray description]); [muArray removeObjectAtIndex:1]; NSLog(@"%s = %@",__FUNCTION__,[muArray description]); }