izik461
izik461

Reputation: 1173

Bundle.main.path(forResource:) returns nil

For reasons unknown to me I cannot locate file:

let bundlePath = Bundle.main.path(forResource: "REGION_DETAILS_41", ofType: ".zip")

It's strange, because when I list all files present in resources directory, it is there. I can find other files, but not this one. I've also tried different configurations of searching, like:

let bundlePath = Bundle.main.path(forResource: "REGION_DETAILS_41.zip", ofType: nil)
let bundlePath = Bundle.main.path(forResource: "REGION_DETAILS_41.zip", ofType: "")

but with no success.

EDIT: The following fails as well:

Bundle.main.path(forResource: "REGION_DETAILS_41", ofType: "zip")

EDIT2: I verify if it's present there by checking what is my resources folder and checking its contents:

Bundle.main.resourcePath
FileManager.default.contentsOfDirectory(atPath: myResourcesFolder)

enter image description here

Also I've checked in finder it's actually there.

It is included in copy Bundle Resources:

enter image description here

Upvotes: 2

Views: 5105

Answers (2)

izik461
izik461

Reputation: 1173

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.

Upvotes: 2

Rahul Umap
Rahul Umap

Reputation: 2869

First thing is check if you have copied this ZIP file into a bundle at the time adding by looking into Copy Bundle Resource.

Following code is tested and you can able to access zip file through it :

let bundlePath = Bundle.main.path(forResource: "REGION_DETAILS_41", ofType: "zip")

Upvotes: 3

Related Questions