2

I tried to add files to Xcode 16 for loading a react build into webview by following this tutorial https://ditto.live/blog/run-react-locally-in-ios-app:

  1. Right click on the Project(In project navigation at left)
  2. Add files to "<project_name>"
  3. Selected the folder(named 'build') from navigator and clicked "Add"
  4. I get the following dialog:
    enter image description here

The expected image should have been this:

enter image description here

And when I try to list the build folder with:

let docsPath = Bundle.main.resourcePath!.appending("/build")
let fileManager = FileManager.default

do {
    let docsArray = try fileManager.contentsOfDirectory(atPath: docsPath)
    print(docsArray)
} catch {
    print(error)
}

I get "No such file or directory" error in the console.

3 Answers 3

4

You can try the method below; it works for me.

  1. Show Inspector: Choose Folder -> View -> Inspector -> Show Inspector enter image description here

  2. Choose Apply Once to Folder and add your target enter image description here

Sign up to request clarification or add additional context in comments.

2 Comments

Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.
As i understand you are telling us how to add folder as a whole to the project, not how to reference a folder.
3

After you create the folder reference as described by yo1995's answer, also use the file inspector on the folder to change the value of "Build Rules" to "Apply Once To Folder".

This will result in the folder being copied as an opaque single resource, rather than passing all of the files in the folder through to the build system for individual processing.

Comments

0

Xcode 16 has slightly changed the UI for adding files/folders.

The first checkbox in older versions, "Destination: Copy items if needed" is changed into a drop down list. Copy = checked; reference in place = unchecked; move is a newly added action that equals to copy then delete in the older version.

Drop down list 1

The "Add folders" radio buttons group is changed into a drop down list as well. It only appears when you are adding a folder from disk. The options remain the same.

Drop down list 2

To debug file path related issues, one way is to use Xcode > Product > Show Build Folder In Finder, and reveal the content in the app bundle to see how the folders are actually structured in the bundle.

In short, "groups" are logic groupings for the project files only, and all the files are laid flat in the root level of the bundle; "folder references" are actual folders created in the bundle so the files are hierarchical.

Related Apple doc: https://developer.apple.com/documentation/xcode/managing-files-and-folders-in-your-xcode-project

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.