在使用plist文件做本地緩存時(shí),由于是通過代碼創(chuàng)建的,在使用的過程中遇到了the data couldn't be read because it isn't in the correct format問題,

Google了一下,發(fā)現(xiàn)沒有想要的答案便自己查代碼解決。在使用plutil xxx.plist終端命令時(shí) 得到下面信息xxx.plist: Cannot parse a NULL or zero-length data。

原來代碼創(chuàng)建plist文件,在沒有進(jìn)行數(shù)據(jù)存儲的時(shí)候,是一個(gè)空的文件,在你雙擊打開時(shí)是會出現(xiàn)the data couldn't be read because it isn't in the correct format的提示的。這不是你代碼的問題,只是plist里面沒有數(shù)據(jù)而已。但在使用plist存儲數(shù)據(jù)時(shí),如果使用了非法類型的數(shù)據(jù)你一樣是不能進(jìn)行存儲的。所以,再用plist時(shí)要保證你的數(shù)據(jù)類型合法(dictionary,array,data,date,bool,number,string)。