简体   繁体   English

当应用名称包含“空格”时,Bundle.main.path(forResource:ofType:inDirectory :)返回nil

[英]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.

相关问题 Bundle.main.path(forResource:ofType:inDirectory:) 返回 nil - Bundle.main.path(forResource:ofType:inDirectory:) returns nil 当目录和文件名正确时,Bundle.main.path(forResource:ofType:inDirectory :)返回nil - Bundle.main.path(forResource:ofType:inDirectory:) returns nil when directory and filename are correct Bundle.main.path(forResource :)返回nil - Bundle.main.path(forResource:) returns nil URL(fileURLWithPath:Bundle.main.path(forResource:“ ports”,ofType:“ geojson”)!)是零吗? - URL(fileURLWithPath: Bundle.main.path(forResource: “ports”, ofType: “geojson”)!) is nil? 为什么Bundle.main.path(forResource:fileName,ofType:“ txt”)总是返回nil? - why does Bundle.main.path(forResource: fileName, ofType: “txt”) always return nil? 当使用 UIImage(named:“”) 和 Bundle.main.path(forResource:) 合成图像时,为什么性能会有很大差异? - When use UIImage(named:“”) and Bundle.main.path(forResource:) compositing images, why is the performance very different? -[NSBundle pathForResource:ofType:inDirectory:]对于本地化资源返回nil - -[NSBundle pathForResource:ofType:inDirectory:] returns nil for localized resources 在应用程序启动时读取 Bundle.main.path 是否耗时? - Reading Bundle.main.path at the launching of the app is time consuming or not? Bundle.main.url(forResource:“ hello”,withExtension:“ html”)返回nil - Bundle.main.url(forResource: “hello”, withExtension: “html”) is returning nil Bundle.main.url(forResource: &quot;AppleIncRootCertificate&quot;, withExtension: &quot;cer&quot;) == nil - Bundle.main.url(forResource: "AppleIncRootCertificate", withExtension: "cer") == nil
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM