由于实验室项目的需要将数据存入plist,遇到了无法将数据写入plist的情况,现在将遇到的两种问题以及解决方法。
1>.在iOS中,只允许向沙盒中的plist文件写数据
The problem is you are trying to write to a file in the bundle. The only places you are allowed to write to are the caches directory (not what you want) and the documents directory.(http://stackoverflow.com/questions/32807098/cant-write-data-to-plist-in-ios)
2>.当向沙盒中的plist文件写数据无效时
writeToFile:atomically:
对写入的数据结构应属于以下几种如下:
NSString
NSData
NSDate
NSNumber
NSArray
NSDictionary
其他的数据结构是不被接受的,如 null(http://stackoverflow.com/questions/3010363/nsarray-writetofile-fails)