How to store custom binary data in app?

I'm using SwiftUI to create an IOS application. I have some binary files that I need to read from within the application. What is the best way to add these files to my application?

I can always convert them to constant binary arrays in a swift file, but that seems a bit silly to me. I'd much prefer to load the binary file from the bundle (bundle.main.path()) if that's possible. I just can't figure out how to get the files added to the bundle.

I'm using XCode 14.3.1 if it matters.

Answered by szymczyk in 761017022

Place the binary files in the app target's Copy Bundle Resources build phase to add the files to the app bundle.

  1. Open the project editor by choosing the project from the left side of the project window.
  2. Select the app target from the target list on the left side of the project editor.
  3. Click the Build Phases button at the top of the project editor.
  4. Click the disclosure triangle next to the Copy Bundle Resources build phases to see the files that are in the build phase.
  5. Click the Add button below the file list to add the binary files to the build phase.
Accepted Answer

Place the binary files in the app target's Copy Bundle Resources build phase to add the files to the app bundle.

  1. Open the project editor by choosing the project from the left side of the project window.
  2. Select the app target from the target list on the left side of the project editor.
  3. Click the Build Phases button at the top of the project editor.
  4. Click the disclosure triangle next to the Copy Bundle Resources build phases to see the files that are in the build phase.
  5. Click the Add button below the file list to add the binary files to the build phase.
How to store custom binary data in app?
 
 
Q