unable to save plist ios

前端 未结 3 1401
慢半拍i
慢半拍i 2021-01-26 13:53

I m able to save the plist file in Simulator but I m not able to save the Plist file in the device. Any suggestion.

I m using

NSString* dictPath = [[NSB         


        
3条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-26 14:05

    You need to save the plist in Documents directory

    to write

    NSString *mainBundlePath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
    NSString *dictPath = [mainBundlePath stringByAppendingPathComponent:@"Dictionary"];
    NSDictionary * dict = ...; //Construct your dictionary
    [dict writeToFile:dictPath atomically: YES];
    

    to read

    NSDictionary * dict = [[NSDictionary alloc] initWithContentsOfFile:dictPath];
    

提交回复
热议问题