【发布时间】:2015-11-12 09:17:03
【问题描述】:
我试图在我的包的子目录的子目录中找到一个文件。我使用这段代码创建了一个带有init(contentsOfFile:) 的 UIImage。
let resource = NSBundle.mainBundle().pathForResource("1g", ofType: "jpg", inDirectory: "Level1")
let image = UIImage(contentsOfFile: resource!)
我做错了什么?
编辑:
这是因为您在 xcode 编辑器中创建的组不会影响实际路径。
let resource = NSBundle.mainBundle().pathForResource("1g", ofType: "jpg", inDirectory: nil)
或let resource = NSBundle.mainBundle().pathForResource("1g", ofType: "jpg")
【问题讨论】:
-
无法获取资源。所以通过正确的路径。右键单击1g.jpg并在finder中显示,然后将项目名称后的路径粘贴到“inDirectory:????”中?标记位置
-
我的完整路径:file:///Users/user/Desktop/MattNeuburg/pathFinder/pathFinder/1g.jpg 我尝试了 pathFinder/1g.jpg、pathFinder、pathFinder/pathFinder。没有工作:/
-
您能通过 Dropbox 或其他方式分享您的项目,以便我看看吗?
-
刚刚想通了..