0
0

More than 5 years have passed since last update.

writeToURLの使い方

Last updated at Posted at 2014-02-01

writeToURLの使い方がイマイチよく分からなかったけど、
こんな感じにしたら一応ファイル出力できました。

    NSArray *array = @[ @"ABC", @12, @3.14, @YES, [NSDate date] ];
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES);
    NSString *directoryPath = [paths lastObject];
    NSLog(@"path[%s]", [directoryPath fileSystemRepresentation]);
    NSURL *fileURL = [NSURL fileURLWithPathComponents:@[directoryPath, @"abc.plist"]];
    if ([array writeToURL:fileURL atomically:YES]) {
        NSLog(@"OK");
    }
    else {
        NSLog(@"NG");
    }
    NSArray *array2 = [NSArray arrayWithContentsOfURL:fileURL];
    NSLog(@"array2: %@", array2);
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0