在使用plist文件做本地緩存時,由于是通過代碼創建的,在使用的過程中遇到了the data couldn't be read because it isn't in the correct format問題,
Google了一下,發現沒有想要的答案便自己查代碼解決。在使用plutil xxx.plist終端命令時 得到下面信息xxx.plist: Cannot parse a NULL or zero-length data。
提示第77行有錯誤, 找到修改以后, 編譯正確
原來代碼創建plist文件,在沒有進行數據存儲的時候,是一個空的文件,在你雙擊打開時是會出現the data couldn't be read because it isn't in the correct format的提示的。這不是你代碼的問題,只是plist里面沒有數據而已。但在使用plist存儲數據時,如果使用了非法類型的數據你一樣是不能進行存儲的。所以,再用plist時要保證你的數據類型合法(dictionary,array,data,date,bool,number,string)。