简体   繁体   中英

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? 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. this causes the Bundle.main.path to return nil

强烈建议还是使用与网址相关的API

Bundle.main.url(forResource: "testFile", withExtension: "rtf") 

Swift 4.1它可以与我一起读取我的应用程序Bundle.main.paths中的mp3文件(forResourcesOfType:“ mp3”,inDirectory:“”)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM