[NSBundle mainBundle] returns same path as [NSBundle bundleForClass: [self class]] in framework

Hi ;-)

I develop a framwork along with a testApp that both belongs to the same workspace.

I added a file to my framework, it is in the Copy Ressources part of the Build Phases, I double checked the name, no issues here. I want to load this file using pretty straightforward code using [NSBundle bundleForClass: [self class]] as follows

  NSBundle *bundle = [NSBundle bundleForClass: [self class]];
  NSString *jsonPath = [bundle pathForResource:@"deviceSafeAreas" ofType:nil];

It always returns nil. The strange part is that if I print the bundlePath iVar, I get the same path for both [NSBundle mainBundle] and [NSBundle bundleForClass: [self class]]. I even tried to "force" the [self class] into [MyClass class], but I get the same result. If I inspect the derivedData, the file is present at the root of the framework

This folder is inside ~/Library/Developer/Xcode/DerivedData/XXXXXX/Build/Products/Debug-iphonesimulator

My guess is that since I do not really embeed the framework, but use it from the workspace, xcode messes things up and is not able to properly get the framework's bundle, mbut I may be wrong.

Any help would be appreciated. thanks.

FYI, I also tried to create a bundle inside the framework, the issue is still the same : the bundle is visible in the derived data framework's folder, but the path inside the app is wrong.

I also tried a couple of things :

  • If I choose "embeed" (the signing part is not relevant), I can access the framework inside the privateFrameworkPath of the Bundle.main, but it's not a solution per se as we distribute our framework through cocoapod and frameworks are not embeeded
  • I tried to generate a standalone xcframework and use it in a project (to check the workspace guess) : the issue is the same. If I print the [[NSBundle bundleForClass: [self class]] bundlePath], I get the same path as the main bundle's path :-/
[NSBundle mainBundle] returns same path as [NSBundle bundleForClass: [self class]] in framework
 
 
Q