ioswebview

XCode 16 How to create folder reference?


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.


Solution

  • 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