我有两个文件,都命名为 GoogleService-Info.plist
。一个在文件夹 Resources -> Staging 中,另一个在文件夹 Resources -> Production 中。它们都被添加到 Copy Bundle Resources
。我访问其中一个的代码是这样的:
if let path = Bundle.main.path(forResource: "GoogleService-Info", ofType: "plist", inDirectory: "Resources/Staging") {
print("this should work but doesn't")
}
它总是返回零。为什么找不到文件?
最佳答案
资源将放在您的应用程序包的根目录中。唯一一次在应用程序包中获取文件夹是在项目中创建文件夹引用时。这些将是蓝色文件夹,而不是黄色。
将您的代码更改为(删除 inDirectory
部分):
if let path = Bundle.main.path(forResource: "GoogleService-Info", ofType: "plist") {
print("this should work but doesn't")
}
关于ios - pathForResource 返回 nil,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48470640/