Can't write on plist file after deploying on iPhone

只愿长相守 提交于 2019-12-25 03:36:16

问题


Dear all. I am facing a problem. I can read and write on plist while working on simulator of xcode. but when I deploy the app in iPhone, i can't write on plists.

I have created a sample project having 2 button on it. By one button, I can display the text from plist. By second button, I try to write on that plist. But the writing doesn't happen. The app doesn't crash while clicking on the second button. I can't understand the problem in my code.

/*code is given below*/
-(void)writePlist:(NSString *)fname withArray:(NSMutableArray *) myArray
{
   NSString * path = nil;
   path = [(NSString *) [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES) objectAtIndex:0] stringByAppendingPathComponent:fname];
   [myArray writeToFile:path atomically:NO];   
}

回答1:


It could be that myArray variable contains non-serializable object values (probably custom objects or something like that).




回答2:


Does the directory you are trying to write to exist? You may want to verify its existence (and create it if it isn't already there) before trying to write a file into it.



来源:https://stackoverflow.com/questions/5106921/cant-write-on-plist-file-after-deploying-on-iphone

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!