0

From this question: How can I get all image names in asset catalog group?

I want to access a file created in the root of an App in Swift.

My App is called Challenge and my script is

# Type a script or drag a script file from your workspace to insert its path.
#!/bin/sh
>./Challenge/fileNames.txt
for FILE in ./Challenge/Images.xcassets/actions/*; do
echo $FILE >> ./Challenge/fileNames.txt
done

I have tried

    let fileManager = FileManager.default
    let imagePath = Bundle.main.resourcePath! + "fileNames.txt"
    let imageNames = try! fileManager.contentsOfDirectory(atPath: imagePath)

And many other combinations .

This is not homework, I have tried various solutions but as I am not sure where the file is within the file system (how the root can be accessed within the App) I seem unable to locate the file.

Question: How to read ./Challenge/fileNames.txt from an App called challenger, created by a script during the build phase.

WishIHadThreeGuns
  • 1,225
  • 3
  • 17
  • 37

1 Answers1

0

The file is located in the main bundle folder, not resource path:

let fileManager = FileManager.default
let imagePath = Bundle.main.path(forResource: "fileName", ofType: "txt")
let content = try! String(contentsOfFile: imagePath)
kubrick G
  • 856
  • 6
  • 10