I create an iOS framework named TestFramework in swift on Xcode 11, and set its Mach-O Type to static library in the target build settings.
I add a xib file named MyViewController.xib with MyViewController.swift into the framework project, and made the MyViewController class public.
Then I create a new iOS app project and add the TestFramework into the project as a embed framework.
I use the following code to test the framework.
let bundle = Bundle(for: MyViewController.self) print("bundle:", bundle) let vc = MyViewController(nibName: "MyViewController", bundle: bundle) print("ViewController:", vc) I get the result:
bundle: NSBundle </Users/xxx/TestApp.app> (loaded) ViewController: <TestFramework.MyViewController: 0x7fce75403c40> It seems everything's ok. But when I try to present the viewcontroller, it failed. I got the NSInternalInconsistencyException.
self.present(vc, animated: false, completion: nil) The exception detail:
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Could not load NIB in bundle: 'NSBundle </Users/xxx/TestApp.app> (loaded)' with name 'MyViewController'' Any ideas. Thanks.
Bundle(for:)initializer did not return you the bundle you expected. It looks like it returned you the main bundle. Try to compare the bundle you got fromBundle(for:)andBundle.main.bundleequalsBundle.main. And after I changed the framework back to Dynamic, everything's ok. Thanks. But should I use dynamic since some tutorials told me should use static library instead.