本地化資料

2021-07-22 06:11:34 字數 2683 閱讀 9063

本地化資料是乙個專案中比較重要的一部分。今天自己來整理下資料本地化的一些知識,方便以後使用

本地化資料的基本方法:1、plist檔案(屬性列表)2、preference(偏好設定)3、nskeyedarchiver(歸檔)4、sqlite    5、coredata

一、沙盒

1、沙盒的目錄結構

documents // itunes會備份該目錄下的內容

library

caches // itunes不會備份該目錄下的內容

preferences // itunes會備份該目錄下的內容

tmp//程式退出後該目錄會被清空

2、獲取目錄的路徑的方法

nsarray *bundledocumentpatharr = nssearchpathfordirectoriesindomains(nsdocumentdirectory, nsuserdomainmask, yes);  //nscachedirectory nslibrarydirectory

nsstring *bundledocumentpathstr = [bundledocumentpatharr objectatindex:0];

nsstring *temporyarypath = nstemporarydirectory();

nslog(@"temporyarypath--%@",temporyarypath);

3、nssearchpathfordirectoriesindomains方法引數介紹

// nssearchpathdirectory directory: 第乙個引數指定了搜尋的路徑名稱,nsdocumentdirectory表示是在documents中尋找.nscachedirectory的話就是在cache檔案中尋找.

//nssearchpathdomainmask domainmask 第二個引數限定了檔案的檢索範圍只在沙箱內部.其意義為使用者電腦主目錄.也可以修改為網路主機等.

//bool expandtilde 最後乙個引數決定了是否展開波浪線符號.展開後才是完整路徑,這個布林值一直為yes.

二、檔案操作

nsfilemanager *filemanager =[nsfilemanager defaultmanager];

建立檔案

[filemanager createfileatpath:filename contents:nil attributes:nil];

建立資料夾:[filemanager createdirectoryatpath:documentspath withintermediatedirectories:yes attributes:nil error:nil]

attributes:介紹

這個鍵的值需要設定為乙個表示布林值的nsnumber物件,表示建立的目錄是否是唯讀的。

這個鍵的值需要設定為乙個nsdate物件,表示目錄的建立時間。

這個鍵的值需要設定為乙個nsstring物件,表示這個目錄的所有者的名字。

這個鍵的值需要設定為乙個nsstring物件,表示這個目錄的使用者組的名字。

這個鍵的值需要設定為乙個表示unsigned int的nsnumber物件,表示目錄的組id。

這個鍵的值需要設定乙個nsdate物件,表示目錄的修改時間。

這個鍵的值需要設定為乙個表示unsigned int的nsnumber物件,表示目錄的所有者id。

這個鍵的值需要設定為乙個表示short int的nsnumber物件,表示目錄的訪問許可權。

這個鍵的值需要設定為乙個表示unsigned long的nsnumber物件,表示目錄的引用計數,即這個目錄的硬鏈結數。

這樣,通過合理的設計attributes字典中的不同鍵的值,這個介面所建立的目錄的屬性就會基本滿足我們的需求了。

三、plist檔案

1、可以儲存以下型別的資料

nsarray;

nsmutablearray;

nsdictionary;

nsmutabledictionary;

nsdata;

nsmutabledata;

nsstring;

nsmutablestring;

nsnumber;

nsdate;

2、將內容寫入檔案中

nsdictionary *dic = @;

[dic writetofile:filename atomically:yes];

儲存時使用writetofile: atomically:方法。 其中atomically表示是否需要先寫入乙個輔助檔案,再把輔助檔案拷貝到目標檔案位址。這是更安全的寫入檔案方法,一般都寫yes。

3、讀取檔案中的內容

nsdictionary *dic2 = [nsdictionary dictionarywithcontentsoffile:filename];

四、preference就是nsuserdefaults

本地化 日誌本地化

目錄 概要執行時日誌 國際化與本地化 定義你的本地化日誌資訊mymsg enum package org.skzr.logging basename charset utf 8 value org.skzr.logging.msglocallog public enum mymsg 定義國際化檔案o...

Swift 匯出本地化和匯入本地化

一。匯出本地化 1.如下設定,來新增本地化語言 2.匯出檔案 儲存完成後 生成以下兩個檔案 然後用xlifftool 分別開啟以上兩個檔案 在以下顯示 no translation 的地方,新增英文所要替代的語言,如下所示 然後儲存就可以了 二.匯入本地化 1.按如下步驟 2.新增 3新增後出現以下...

UI基礎 資料本地化

方法一 儲存在偏好設定中 將資料儲存到偏好設定中,不需要關心路徑在 不要儲存大資料,比如。存 偏好設定物件 nsuserdefaults defaults nsuserdefaults standarduserdefaults defaults setobject jack forkey name ...