介紹如何使用mac與ios上的文件系統(tǒng)
-
獲得指向文件管理器的引用
- NSFileManager :獲得這個引用才能使用文件系統(tǒng)
引用mac 與 ios 的關(guān)鍵目錄NSSearchPathForDirectoriesInDomains
查看并且修改文件屬性
- 獲取文件屬性
- NSFilemanager attributesOfItemAtPath: error :
返回一個字典:此字典列出目標(biāo)文件或者目錄的所有屬性
-
獲得
指定目錄中的文件列表- filemanager contentsOfDirectoryAtPath: error :
- fileManager subpathsOfDirectoryAtPath: error :
-
管理
文件與目錄- 管理
目錄
1.createDirectoryAtPath: withIntermediateDirectories: attributes: error: 新建目錄
2.moveItemAtPath: toPath: error :
3.removeItemAtPath: toPath: error :
4.copyItemAtPath: toPath: error:- 管理
文件
1.NSFileManager createFileAtPath:contents: attributes:
要想創(chuàng)建文件,需要使用nsdata ,nsdata 用于處理數(shù)據(jù)與內(nèi)容.
- 管理
-
使用NSData類處理數(shù)據(jù)
- writeToFile:options:? :
-
管理大量占用內(nèi)存的緩存對像
- NSCache *cache
- 將緩存作為屬性存放在試圖控制器中并在viewDidLoad 中實例化緩存,這意味著只要活動控制器處于活動狀態(tài),就可以使用緩存.
NSString*key=@"regular-logo";
NSPurgeableData*data=[cache objectForKey:key];
為了不每次都重新創(chuàng)建緩存,我們需要判斷有沒有相關(guān)的緩存已經(jīng)存在
(現(xiàn)在對象已經(jīng)被緩存,你可以隨時通過鍵再次加以檢索)