ios 檔案儲存的五種方式

2022-09-12 03:15:13 字數 598 閱讀 8322

為了將應用資料儲存到硬碟中,ios提供了:plist(屬性列表),資料庫儲存(sqlite),物件歸檔(nscoding),core data,nsuserdefaults;

1.plist屬性列表操作用來儲存一些固定的資料型別:nsarray nsstring nsdata nsnumber nsdictionary nsdata等簡單物件,適合小資料的操作,速率很高。

2.資料庫(sqlite) 不解釋

3.物件歸檔:(nscoding)plist可以對固定型別的資料進行儲存操作,但當面對複雜的資料或者自定義的資料型別時,plist不再適用,這時就可以適用物件歸檔(也稱固化)。但其缺點是資料必須整存整取:要更新資料的任何改動,必須重寫整個檔案。

4.nsuserdefaults:當面對輕量級資料(例如登入名和登入密碼),此時使用plist顯得麻煩,可以適用nsuserdefaults.其支援nsnumber nsstring nsdate nsarray nsdictionary bool等型別的資料,可以像讀取字串一樣操作。其資料主要儲存在應用程式內建的乙個plist檔案裡(實際對應沙盒的/library/prefereces 中的plist檔案裡)。

5.core data 見其他隨筆

iOS 檔案的三種儲存方式

1.歸檔形式 歸檔解檔可以針對所有的物件 必須要遵守協議 nscoding nsstring path nssearchpathfordirectoriesindomains nsdocumentdirectory,nsuserdomainmask,yes 0 abc.date nskeyedarc...

ios執行緒的五種使用方式

第一種方式 手動建立並啟動 nsthread t nsthread alloc initwithtarget self selector selector method object nil t start 第二種方式 類方法 nsthread detachnewthreadselector sel...

IOS四種儲存方式

1 nskeyedarchiver 採用歸檔的方式來儲存資料,該資料物件需要遵守nscoding協議,並且該物件對應的類必須提供encodewithcoder 和initwithcode 方法。前乙個方法告訴系統怎麼對物件進行編碼,後乙個方法告訴系統怎麼對物件進行解碼。缺點 只能一次性歸檔儲存以及一...