文件存儲(chǔ)類型總結(jié)

1、Property Lists

屬性列表,擴(kuò)展名為plist。

  • Property list有三種存儲(chǔ)方式:XML, binary format, “old-style” ASCII format inherited from OpenStep。old-style format的序列化API是只讀的。

A property list can be stored in one of three different ways: in an XML representation, in a binary format, or in an “old-style” ASCII format inherited from OpenStep. You can serialize property lists in the XML and binary formats. The serialization API with the old-style format is read-only.

  • 數(shù)據(jù)大小限制(幾百kb內(nèi))

For situations where you need to store small amounts of persistent data—say less than a few hundred kilobytes—property lists offer a uniform and convenient means of organizing, storing, and accessing the data.
In some situations, the property-list architecture may prove insufficient. If you need a way to store large, complex graphs of objects, objects not supported by the property-list architecture, or objects whose mutability settings must be retained, use archiving.

  • 如果我們的對(duì)象全由NSDictionary, NSArray, NSString, NSDate, NSData, 或NSNumber類派生,我們可以創(chuàng)建property list。

  • XML property list 比 binary 格式的可移植性好,可以手動(dòng)編輯,但是binary property lists 兼容性好,需要的存儲(chǔ)空間少,讀寫速度要優(yōu)于XML property lists。通常來(lái)說(shuō),如果你的property list相對(duì)較小,XML property lists的優(yōu)點(diǎn)會(huì)戰(zhàn)勝它相對(duì)binary property lists的I/O速度,難兼容的缺點(diǎn)。

  • 如果你有大量數(shù)據(jù),binary property lists, keyed archives,或自定義數(shù)據(jù)格式會(huì)是更好的解決方案。

2、NSUserDefaults

  • NSUserDefaults,提供了與默認(rèn)系統(tǒng)交互的程序接口。

  • 默認(rèn)系統(tǒng)允許應(yīng)用去自定義它的行為來(lái)符合用戶的偏好。所以它主要是用來(lái)存儲(chǔ)配置信息。

  • 支持的數(shù)據(jù)類型有:floats,doubles,integers,Booleans,URLs,NSData,NSString,NSNumber,NSDate,NSArray和NSDictionary。如果還想存儲(chǔ)其他類型的對(duì)象,需要使用NSData對(duì)它們進(jìn)行歸檔。

  • 事實(shí)上,NSUserDefaults就是把數(shù)據(jù)保存在property list中

3、Archive

歸檔

Archives provide a means to convert objects and values into an architecture-independent stream of bytes that preserves the identity of and the relationships between the objects and values.

  • 如果對(duì)象是NSString、NSDictionary、NSArray、NSData、NSNumber等類型,可以直接用NSKeyedArchiver進(jìn)行歸檔和恢復(fù)。

  • 不是所有的對(duì)象都可以直接用這種方法進(jìn)行歸檔,只有遵守了NSCoding協(xié)議的對(duì)象才可以。

3、DB

數(shù)據(jù)庫(kù)可以提供對(duì)數(shù)據(jù)更加高級(jí)的操作,這是其他方式不能提供的。當(dāng)涉及到建模,查詢,遍歷,持久化復(fù)雜的對(duì)象圖,就可以采用數(shù)據(jù)庫(kù)來(lái)實(shí)現(xiàn)數(shù)據(jù)持久化。

  • SQLite
  • Core Data
  • FMDB
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • pyspark.sql模塊 模塊上下文 Spark SQL和DataFrames的重要類: pyspark.sql...
    mpro閱讀 9,911評(píng)論 0 13
  • mean to add the formatted="false" attribute?.[ 46% 47325/...
    ProZoom閱讀 3,175評(píng)論 0 3
  • 相關(guān)鏈接:https://developer.apple.com/library/archive/document...
    ngugg閱讀 453評(píng)論 0 1
  • 英文文檔,一開(kāi)始我也是抗拒的,邊翻譯邊看,也就花費(fèi)了1個(gè)小時(shí)基本就閱讀過(guò)了,我的英文基礎(chǔ)其實(shí)很差。附上鏈接:鏈接:...
    lonecolonel閱讀 10,408評(píng)論 3 1
  • 函數(shù)調(diào)用 Built-in Functions abs(x) Return the absolute value ...
    叫我七夜閱讀 1,310評(píng)論 0 0

友情鏈接更多精彩內(nèi)容