iOS Assets

if you want to access a folder Foo in your project root you first add it to Custom Xcode Resource Folders - this will cause it to be copied into the app bundle that’s built. then to find the path to Foo/bar.txt you can do one of two things.

  1. if you want to keep things cross-platform then you need to read this thread as it describes how to implement a getSharedResourceFolder() method which will point correctly to assets folders across various os’s. then you can call getSharedResourceFolder().getChildFile("Foo/bar.txt")

  2. if you’re just focused on the mac you can use the native functionality.

const juce::File pathToFoo() {
  NSBundle *mainBundle = [NSBundle mainBundle];
  NSString *filePath = [mainBundle pathForResource:@"bar"
                                            ofType:@"txt"
                                       inDirectory:@"Foo"];
  juce::File file([filePath UTF8String]);
  return file;
}

and this will work on ios and macos (which have slightly different app bundle structures).
note this will have to be in a .mm file for it to compile correctly, and that may cause issues with cross-platform builds (see the above thread for more info there)

1 Like