Bundle.main returns the wrong bundle inside a framework

Originator:thomas.mellenthin
Number:rdar://50347914 Date Originated:2019-04-30
Status:open Resolved:
Product:Xcode Product Version:10.2.1
Classification:other Reproducible:always
 
Summary:

     Bundle.main inside a framework returns the wrong data.

     [From the docs:](https://developer.apple.com/documentation/foundation/bundle/1410786-main)
     "_For code running in a framework, the main bundle offers access to the framework’s bundle directory_."

     However, when breaking in the provided test method, the main bundle is referring to Xcode:
     
     ```
     (lldb) po Bundle.main
     NSBundle </Applications/Xcode-10.1.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/Library/Xcode/Agents> (loaded)
     ```

     I would expect the frameworks bundle here.


Steps to Reproduce:

  * run the test

Expected Results:

  * The test is green, the frameworks bundle is returned by .main

Actual Results:

 * The test fails, because the bundle of Xcode is returned

Version/Build:

Xcode 10.2.1 (10E1001)

Configuration:

osx 10.14.4 (18E226)

Comments

Sample project

https://www.dropbox.com/s/gos4a58sunokdmm/rdar-50347914.zip?dl=0

By thomas.mellenthin at April 30, 2019, 8:49 p.m. (reply...)

Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!