在使用plist文件做本地緩存時(shí),由于是通過(guò)代碼創(chuàng)建的,在使用的過(guò)程中遇到了the data couldn't be read because it isn't in the correct format問(wèn)題,
Google了一下,發(fā)現(xiàn)沒(méi)有想要的答案便自己查代碼解決。在使用plutil xxx.plist終端命令時(shí) 得到下面信息xxx.plist: Cannot parse a NULL or zero-length data。
原來(lái)代碼創(chuàng)建plist文件,在沒(méi)有進(jìn)行數(shù)據(jù)存儲(chǔ)的時(shí)候,是一個(gè)空的文件,在你雙擊打開(kāi)時(shí)是會(huì)出現(xiàn)the data couldn't be read because it isn't in the correct format的提示的。這不是你代碼的問(wèn)題,只是plist里面沒(méi)有數(shù)據(jù)而已。但在使用plist存儲(chǔ)數(shù)據(jù)時(shí),如果使用了非法類型的數(shù)據(jù)你一樣是不能進(jìn)行存儲(chǔ)的。所以,再用plist時(shí)要保證你的數(shù)據(jù)類型合法(dictionary,array,data,date,bool,number,string)。