美文网首页
补充笔记03-沙盒及获取资源路径

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

作者: 没有北方的南方 | 来源:发表于2016-08-12 20:58 被阅读7次

    沙盒及获取资源路径

    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-沙盒及获取资源路径

          本文链接:https://www.haomeiwen.com/subject/mesesttx.html