【问题标题】:Not able to access pod swift file, after installing pod安装 pod 后无法访问 pod swift 文件
【发布时间】:2019-07-27 22:43:29
【问题描述】:

我使用 raywenderlich tutroial link 创建了一个 pod,一切正常

  • 创建
  • 安装和
  • 也在导入 pod
    但是当我试图访问视图控制器时,它说

    use of unresolved identifier 'file name'

    我尝试 cmd+click 跳转到文件的定义,它也将我导航到文件

    代码实现

    let bundle = Bundle(for: SDKSplashVC.self) // error here - Use of unresolved identifier 'SDKSplashVC'
    let storyboard = UIStoryboard(name: "SDKSplash", bundle: myBundle)
    let controller = storyboard.instantiateViewController(withIdentifier: "SDKSplashVC")
    self.present(controller, animated: true, completion: nil)
    

    我已经导入了 pod,交叉签入了托管方案和构建阶段,我的自定义 pod 已列出,但仍然存在错误

    任何帮助都会非常有帮助。 谢谢

  • 【问题讨论】:

    • 请提供您在 pod 中如何定义 SDKSplashVC 的代码
    • @Leo SDKSplashVC 是普通的视图控制器,只有 viewDidLoad func()

    标签: ios swift cocoapods podspec


    【解决方案1】:

    在教程中,作者使用PickFlavorViewController 类,它在RWPickFlavor cocoa pod 中定义。

    let bundle = Bundle(for: PickFlavorViewController.self)
    

    您可以查看并查看此 pod here 中的所有文件。

    Docs 说您可以使用Bundleinit(for:) 初始化程序来根据该框架中定义的类定位框架包。

    您收到错误是因为未定义 SDKSplashVC。你需要这样写:

    import UIKit
    
    public class SDKSplashVC: UIViewController {}
    

    确保类定义为public

    【讨论】:

    • 我错过了公共访问说明符,谢谢@Leo
    猜你喜欢
    • 1970-01-01
    • 2022-01-15
    • 1970-01-01
    • 1970-01-01
    • 2020-09-23
    • 1970-01-01
    • 2020-07-06
    • 2020-10-11
    • 2021-01-12
    相关资源
    最近更新 更多