let myPath = Bundle.main.path(forResource: "Settings", ofType: ".png")
print(myPath!)
Run Code Online (Sandbox Code Playgroud)
为什么在我尝试打印此图像时会崩溃?
崩溃是在展开...错误时发现nil的著名的意外。除非可以保证不使用感叹号,否则请不要使用感叹号nil。
文件不存在或(很可能)您的类型(扩展名) png不存在.png
let myPath = Bundle.main.path(forResource: "Settings", ofType: "png")
Run Code Online (Sandbox Code Playgroud)
但是,如今,与URL相关的API更可取
let myURL = Bundle.main.url(forResource: "Settings", withExtension: "png")
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
242 次 |
| 最近记录: |