如何在swift中从外部框架呈现视图控制器?

Hus*_*ala 6 frameworks objective-c ios swift

我用一个名为"AuthenticationViewController.h"的视图控制器创建了一个带有nib"AuthenticationViewController.xib"的框架.并且要测试的示例项目已经用于呈现AuthenticationViewController.在Objective-C:

NSString *frameworkDirPath = [[NSBundle mainBundle] privateFrameworksPath];
NSString *frameworkBundlePath = [frameworkDirPath stringByAppendingPathComponent:@"xxx.framework"];
NSBundle *frameworkBundle = [NSBundle bundleWithPath:frameworkBundlePath];
AuthenticationViewController *authenticationViewController = [[AuthenticationViewController alloc]initWithNibName:@"AuthenticationViewController" bundle:frameworkBundle];
authenticationViewController.delegate = self;
[self presentViewController:authenticationViewController animated:YES completion:nil];
Run Code Online (Sandbox Code Playgroud)

哪个适合我.

但是当我使用以下代码时Swift:

let frameworkBundle = NSBundle(identifier: "xxx")

let authViewControler :AuthenticationViewController = AuthenticationViewController.init(nibName: "AuthenticationViewController", bundle: frameworkBundle)
authViewControler.delegate = self
self.presentViewController(authViewControler, animated: true, completion: nil)
Run Code Online (Sandbox Code Playgroud)

该应用程序崩溃错误: -

因未捕获的异常'NSInternalInconsistencyException'而终止应用程序,原因:'无法在bundle中加载NIB:'NSBundle(loaded)',名称为'AuthenticationViewController''

Lum*_*lxk 2

NSBundle(identifier: "SendOTPFramework"),不是NSBundle(path: <#T##String#>)?您确定有可用的标识符吗?您在不同的语言中使用了不同的函数。