iOS 資料儲存方式一之plist檔案儲存

2021-08-01 21:31:07 字數 1078 閱讀 3969

plist檔案,實際上也就是xml檔案。

ios開發中,對於一些小型的資料儲存,可以用到plist檔案儲存。

plist儲存能存nsarray、nsdictionary等,一般能寫出writetofile:這個方法的物件都可以使用plist儲存,存放的路徑一般在沙盒的document檔案目錄下。

plist檔案的寫入:

//獲取沙盒document路徑

nsstring *currentpath = nssearchpathfordirectoriesindomains(nsdocumentdirectory, nsuserdomainmask, yes)[0];

nsdictionary *dictionary = @;

//若之前沒有該檔案,會自動建立該檔案

if ([dictionary writetofile:filepath atomically:yes])

plist檔案的讀取:

nsdictionary *dict = [nsdictionary dictionarywithcontentsoffile:filepath];
刪除plist檔案:

nsfilemanager *manager = [nsfilemanager defaultmanager];

[manager removeitematpath:filepath error:nil];

檢視生成的plist檔案:

nslog(@"%@",nssearchpathfordirectoriesindomains(nsdocumentdirectory, nsuserdomainmask, yes));
用這句**獲取沙盒中的document路徑,然後開啟finder

ios 資料儲存方式

今天發現一篇好文章,忍不住收藏下來 所謂的持久化,就是將資料儲存到硬碟中,使得在應用程式或機器重啟後可以繼續訪問之前儲存的資料。在ios開發中,有很多資料持久化的方案,接下來我將嘗試著介紹一下5種方案 在介紹各種儲存方法之前,有必要說明以下沙盒機制。ios程式預設情況下只能訪問程式自己的目錄,這個目...

iOS中資料儲存方式

首先我們來了解一下ios中資料儲存有哪些方式 xml 屬性列表 plist 歸檔 plist 全名是 property list,屬性列表檔案。它是一種用來儲存序列化後的物件的檔案。屬性列表檔案的擴充套件名為 plist,因此通常被稱為 plist 檔案。檔案是 xml格式的。它是以 key val...

iOS 資料儲存方式介紹

ios常用資料儲存方式主要有5種 1 plist xml屬性列表歸檔 2 偏好設定 3 nskeyedarchiver歸檔 儲存自定義物件 4 sqlite3 資料庫,關係型資料庫,不能直接儲存物件,要編寫一些資料庫sqlite語句,我部落格裡有一篇文章關於sqlite3資料庫基本操作的 5 cor...