为什么 Bundle.main.path(forResource: "testFile", ofType: "rtf")
当应用程序名称有空格时返回 nil?有人遇到过这个吗?也许能够修复?如果我删除应用程序名称中的“空格”,则不会发生错误。
当我打印路径时,结果是 /Users/<user>/Library/Developer/CoreSimulator/Devices/915D4A93-D812-4180-A49E-6BFA3BD77986/data/Containers/Bundle/Application/8623072B-7528-463C-971F-ECD1FB89BDDB/Test Application.app/testFile.rtf
您可能会注意到该应用程序的名称“Test Application.app”上有空格。这会导致 Bundle.main.path
返回零
最佳答案
无论如何都强烈建议使用 URL 相关的 API
Bundle.main.url(forResource: "testFile", withExtension: "rtf")
关于ios - Bundle.main.path(forResource :ofType:inDirectory:) returns nil when app name contains "space",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46293390/