补充笔记03-沙盒及获取资源路径

沙盒及获取资源路径

import UIKit

class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        //沙盒结构:mainBundle, Documents, Library, tmp
        //获取app沙盒位置,每次运行位置都会发生改变
        let mianPath = NSBundle.mainBundle().bundlePath
        print(mianPath)
        
        let path = "Users/apple/Desktop"
        let url = NSURL.fileURLWithPath(path)
        let str = url.absoluteString
        print(url)
        print(str)
        
        
        let resPath = NSBundle.mainBundle().pathForResource("more color", ofType: "png")
        print(resPath)
        
        //获取图片资源位置及url
        let resUrl = NSURL.fileURLWithPath(resPath!)
        
        let resUrl1 = NSBundle.mainBundle().URLForResource("more color", withExtension: "png")
        
        print(resUrl)
        print(resUrl1)
        
        //获取应用程序目录,获取沙盒目录下的文件
        let appPath = NSHomeDirectory()
        print(appPath)
        
        let Document = appPath + "/Document"
        let Document1 = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true)
        print(Document)
        print(Document1)
        
        // Do any additional setup after loading the view, typically from a nib.
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }


}

你可能感兴趣的:(补充笔记03-沙盒及获取资源路径)