Not able to write to Plist

前端 未结 2 1006
孤独总比滥情好
孤独总比滥情好 2020-12-21 23:02

I have a very basic question about how to write to a plist. I added a \"Here.plist\" file to my resources folder. The following is my code:

NSString *path =          


        
2条回答
  •  长情又很酷
    2020-12-21 23:45

    You can't write into the bundle. Try writing into the documents directory. For example:

    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];
    NSArray *array = [[NSArray alloc]initWithObjects:@"First", @"Second", @"Third", nil];
    [array writeToFile:[documentsDirectory stringByAppendingPathComponent:@"Here.plist" atomically:YES];
    

提交回复
热议问题