iOS开发之沙盒模式和目录查看

override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
        
        //Home目录,即沙盒目录
        var path = NSHomeDirectory()
        print("Home: \(path)")
        
        //Documtents目录
        path = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true).first!
        print("Documents: \(path)")
        //.DocumentDirectory表示需要搜索Document路径
        //.UserDomainMsak表示搜索范围限制在应用程序沙盒之内
        //true表示根目录是否展开,false不展开
        
        //Library
        path = NSSearchPathForDirectoriesInDomains(.LibraryDirectory, .UserDomainMask, true).first!
        print("Library: \(path)")
        
        //Caches
        path = NSSearchPathForDirectoriesInDomains(.CachesDirectory, .UserDomainMask, true).first!
        print("Caches: \(path)")
        
        //Tmp
        path = NSTemporaryDirectory()
        print("Tmp: \(path)")
    }

 

你可能感兴趣的:(iOS开发之沙盒模式和目录查看)