[英]Bundle.main.path(forResource:ofType:inDirectory:) returns nil when app name contains “space”
Why the Bundle.main.path(forResource: "testFile", ofType: "rtf")
returns nil when the app's name has space? 当应用程序名称中有空格时,为什么
Bundle.main.path(forResource: "testFile", ofType: "rtf")
返回nil? anyone encounter this? 有人遇到这个吗? and perhaps able to fixed?
也许能够解决? The error doesn't occur if I remove the "space" in the app's name.
如果删除应用名称中的“空格”,则不会发生该错误。
When I print the path the result is this /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
as you may notice the app's name "Test Application.app" has space on it. 当我打印路径时,结果是
/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”上有空格。 this causes the Bundle.main.path
to return nil 这导致
Bundle.main.path
返回nil
强烈建议还是使用与网址相关的API
Bundle.main.url(forResource: "testFile", withExtension: "rtf")
Swift 4.1它可以与我一起读取我的应用程序Bundle.main.paths中的mp3文件(forResourcesOfType:“ mp3”,inDirectory:“”)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.