通常这种情况发生在 bundle 中不存在所需资源的情况下。我们可以通过以下方式来解决:
以下是使用 Bundle.main.path(forResource:ofType:) 方法获取资源路径的示例代码:
if let path = Bundle.main.path(forResource: "image", ofType: "png") { let url = URL(fileURLWithPath: path) // 对 url 进行操作 } else { print("资源未找到") }