0

Context: Xcode Version 11.0 beta 2/Swift 5

I want to create a bundle to access on a physical iOS device. I tried all the solutions on How to make an iOS asset bundle?, but to no avail.

I have created a bundle in finder containing the file and subsequently moved to Xcode such that my directory structure looks like this:

  • *Project Name*
  • *Project Name*Tests
  • Products
  • somebundle.bundle
    • somefile.csv

I keep getting the error

the file "somefile.csv" couldn't be opened because there is no such file

when testing.

I am accessing the file through let text = try String(contentsOfFile: Bundle.main.resourcePath! + "/somebundle.bundle/somefile.csv")

But actually, printing the contents of Bundle.main.resourcePath (FileManager.default.contentsOfDirectory(atPath: Bundle.main.resourcePath!)) shows that the bundle is not located in Bundle.main.resourcePath, as this is the output: ["_CodeSignature", "PlugIns", "Base.lproj", "*Project Name*", "Frameworks", "Info.plist", "PkgInfo"]

So, how do I get the bundle into Bundle.main.resourcePath, as the answers to the question at the top seem to suggest should be the case?

Jim
  • 1
  • 3

1 Answers1

1

To access the contents of a Bundle when the app is installed on a physical device you need to ensure that it is copied across during the build.

Go to your Project Settings -> Build Phases -> Copy Bundle resources and make sure that your bundle is listed there.

You will only be able to read the contents from there unless you copy it to the documents folder first before trying to edit/save.

Scriptable
  • 19,402
  • 5
  • 56
  • 72
  • Done, but I still get the error. Also, I only need read access so that's not a concern. – Jim Jun 26 '19 at 14:33
  • can you explain what you have done so far, what the error is, how you are accessing it etc. I think the 'how you are accessing it?' question could be important. update your question with the information and i'll try to help – Scriptable Jun 26 '19 at 14:58
  • Yeah, the problem is twofold: 1. the asset bundle is not inside Bundle.main.resourcePath, as it should be, according to the answers to the questionI linked to at the top 2. the project is not updating on the physical device, as proven by the output indicating a certain unit test has run even after I comment it out; I've narrowed the question down to #1 – Jim Jun 26 '19 at 15:18