swift中的沙盒路径(包含自定义文件路径)

前端之家收集整理的这篇文章主要介绍了swift中的沙盒路径(包含自定义文件路径)前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

github学习地址:https://github.com/potato512/SYSwiftLearning

效果图:


代码示例:

/// home沙盒主目录路径
let pathHome = NSHomeDirectory();
print("home沙盒主目录路径:\(pathHome)")
/// temp临时目录
let pathTemp = NSTemporaryDirectory();
print("temp临时目录:\(pathTemp)")
/// document文档目录
let array = NSSearchPathForDirectoriesInDomains(NSSearchPathDirectory.DocumentDirectory,NSSearchPathDomainMask.UserDomainMask,true);
let pathDecument = array.first!;
print("document文档目录:\(pathDecument)")
/// cache缓存目录
let arrayCache = NSSearchPathForDirectoriesInDomains(.CachesDirectory,.UserDomainMask,true);
let pathCache = arrayCache.first!;
print("cache缓存目录:\(pathCache)")
/// library目录
let arrayLibrary = NSSearchPathForDirectoriesInDomains(.LibraryDirectory,true);
let pathLibrary = arrayLibrary.first!;
print("library目录:\(pathLibrary)")
/// home主目录自定义文件路径
var pathHomeWithName = NSHomeDirectory() as NSString
pathHomeWithName = pathHomeWithName.stringByAppendingPathComponent("devZhang")
print("home主目录自定义文件路径:\(pathHomeWithName)")
/// temp临时目录自定义文件路径
var pathTempWithName = NSTemporaryDirectory() as NSString
pathTempWithName = pathTempWithName.stringByAppendingPathComponent("devZhang")
print("temp临时目录自定义文件路径:\(pathTempWithName)")
/// document文档目录自定义文件路径
var pathDocumentWithName = pathDecument as NSString
pathDocumentWithName = pathDocumentWithName.stringByAppendingPathComponent("devZhang")
print("document文档目录自定义文件路径:\(pathDocumentWithName)")
/// cache缓存目录自定义文件路径
var pathCacheWithName = pathCache as NSString
pathCacheWithName = pathCacheWithName.stringByAppendingPathComponent("devZhang")
print("cache缓存目录自定义文件路径:\(pathCacheWithName)")
/// library目录自定义文件路径
var pathLibraryWithName = pathLibrary as NSString
pathLibraryWithName = pathLibraryWithName.stringByAppendingPathComponent("devZhang")
print("library目录自定义文件路径:\(pathLibraryWithName)")

猜你在找的Swift相关文章