Bundle.Main.Path(Forresource:Oftype:Indirectory:) Returns Nil

Bundle.main.path(forResource:) returns nil

Thanks to https://stackoverflow.com/users/1187415/martin-r:
The file system on iOS devices is case-sensitive: "zip" != "ZIP".
After changing to ZIP it worked perfectly.

Bundle.main.path(forResource... always returns nil when looking for xml file

Try this code:

if let filePath = Bundle.main.url(forResource: "config.xml", withExtension: nil, subdirectory: "/Resources") {

/// Do something with the filePath

}

Bundle.main.path(forResource:ofType:inDirectory:) returns nil when app name contains space

It's highly recommended to use the URL related API anyway

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

pathForResource returns nil

The resources will be put in the root of your app bundle. The only time you will get folders inside your app bundle is when you create folder references in your project. These will be blue folders, not yellow.

Change your code to (remove the inDirectory part):

if let path = Bundle.main.path(forResource: "GoogleService-Info", ofType: "plist") {
print("this should work but doesn't")
}


Related Topics



Leave a reply



Submit