Search code examples
swiftbundle

BundleUrl return nil


I have an application which project hierarchy like this;

ProjectApp
-AppNative
ProjectAppTest
ProjecUIAppTests

I have an public class swift and ı want to get bundleURL :

public class AppBundle {
   
   static var bundle : Bundle = AppBundle.initBundle()
    
   class func initBundle() -> Bundle {
       let podBundle = Bundle(for: AppBundle.self)
       let bundleURL = podBundle.url(forResource: "ProjectApp", withExtension: "bundle")
       return Bundle(url: bundleURL!)!
    }
}

bundleURL return nil. I can not get it. How can I fix it?


Solution

  • I use .bundleURL to access bundleURL;

    public class AppBundle {
       
       static var bundle : Bundle = AppBundle.initBundle()
        
       class func initBundle() -> Bundle {
           let podBundle = Bundle(for: AppBundle.self)
           let bundleURL = podBundle.bundleURL
           return Bundle(url: bundleURL!)!
        }
    }