UI進(jìn)階數(shù)據(jù)本地化之沙盒機(jī)制

ViewController.m中


NSDocumentDirectory 表示要獲取Document文件夾地址

NSUserDomainMask:表示用戶的主目錄

第三個(gè)參數(shù)表示 展開"~"的地址,設(shè)置為YES為完整的路徑.

NSSearchPathForDirectoriesInDomains:獲取的是一個(gè)數(shù)組,數(shù)組織有一個(gè)元素,所以可以直接獲取objectAtIndex:0

第一種獲取文件夾地址的方式

NSString *documentPanthStr=[NSSearchPathForDirectoriesInDomains(NSDocumentationDirectory, NSUserDomainMask, YES)objectAtIndex:0];

NSLog(@"%@",documentPanthStr);

NSString *documentPathstr1=[NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES)objectAtIndex:0];

NSLog(@"%@",documentPathstr1);



//第二種凡是獲取documents文件夾的路徑

//第一步:獲取沙盒主路徑地址


NSString *homePathStr=NSHomeDirectory();

NSLog(@"homePathStr===%@",homePathStr);


//第二步:在沙盒主路徑后面拼接Documents,拼接出來documents文件夾的路徑

NSString *documentPathStr=[homePathStr stringByAppendingPathComponent:@"Documents"];


NSLog(@"documentPathStr==%@",documentPathStr);


NSString *cashStr=[homePathStr stringByAppendingPathComponent:@"Library/Caches"];


NSLog(@"%@",cashStr);


//獲取tmp文件夾的路徑

NSString *tmpStr=NSTemporaryDirectory();

NSLog(@"tmpStr==%@",tmpStr);

最后編輯于
?著作權(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),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

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

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