在 swift 4 中使用来自 cocoapods 的笔尖

Using nibs from cocoapods in swift 4

我制作了一个框架,其中包含一个函数,该函数根据该框架中包含的 xib 显示登录视图。视图的 xib 文件和 swift 文件都称为 AuthenticationViewController

然而,当我尝试在另一个将其用作 pod 的项目中使用此功能时,它失败并显示 "Could not load NIB in bundle...(not yet loaded)' with name 'AuthenticationViewController'"

视图由位于我的 pod/framework 中的以下代码显示:

func authenticate(viewController: UIViewController){
    let bundle = Bundle(for:AuthenticationViewController.self)
    let newViewController = AuthenticationViewController(nibName:"AuthenticationViewController" , bundle: bundle)

    viewController.present(newViewController, animated: true, completion: nil)
}

这里有什么问题?我的 pod 应该有一个单独的捆绑包吗,因为我在调用时只得到一个捆绑包:

Bundle.allBundles

我的 .podspec 文件包含以下部分:

s.resource_bundles = {
"MyPodName" => ["MyPodName/*.xib"]

}

但我尝试使用以下方式加载包:

Bundle(identifier:"MyPodName")

这也行不通。

你应该如何使用来自 pods 的笔尖?

我好像捆绑包不对。我在我的 pod 库中使用这个函数来获取包

- (NSBundle *)getBundle {
    NSBundle *podBundle = [NSBundle bundleForClass:self.classForCoder];
    NSURL *podBundleURL = [podBundle URLForResource:@"MyPodName" withExtension:@"bundle"];
    NSBundle *bundle = [[NSBundle alloc] initWithURL:podBundleURL];
    return bundle;
}

获得捆绑包后,您可以加载视图。此外,运行 在编辑 .podspec 并添加新文件以重新组织文件后安装 pod。

问题是我使用的是:

s.resource_bundles = {
"MyPodName" => ["MyPodName/*.xib"]
}

这似乎不适用于我所做的方法。所以我不得不将 podspec 文件更改为:

s.resources = ["MyPodName/*.xib"]

这让一切正常