【问题标题】:XCTest Xcode 7 beta 3 swift 2 initiate View Controller from storyboard issueXCTest Xcode 7 beta 3 swift 2 从情节提要问题启动视图控制器
【发布时间】:2015-07-15 22:33:57
【问题描述】:

我在 XCTest 设置中有此代码

var passcodeVC:HNPasscodeViewController!
override func setUp() {
    super.setUp()
    let storyboard = UIStoryboard(name: "Main", bundle: NSBundle(forClass: self.dynamicType))
    self.passcodeVC = storyboard.instantiateViewControllerWithIdentifier("HNPasscodeViewController") as! HNPasscodeViewController
    self.passcodeVC.viewDidLoad()
}

Xcode 在这一行给我错误“Could not cast value of type”

self.passcodeVC = storyboard.instantiateViewControllerWithIdentifier("HNPasscodeViewController") as! HNPasscodeViewController

我正在使用带有 Xcode 7 beta 3 的 Swift 2.0。我尝试了捆绑:

nil
NSBundle.mainBundle()
NSBundle(forClass: self.classForCoder) 
NSBundle(forClass: self.dynamicType) (Xcode doesn't autocomplete this but gives me no error)

我还添加了自定义视图控制器类来编译列表和主故事板到测试目标的资源。

有什么想法吗?谢谢

【问题讨论】:

    标签: ios objective-c swift uistoryboard xctest


    【解决方案1】:

    而不是将我的所有自定义类公开给测试目标。我在 swift 2 中使用了这个新的测试声明

    @testable import <my module name>
    

    现在效果很好。

    【讨论】:

      猜你喜欢
      • 2012-06-23
      • 1970-01-01
      • 2017-07-08
      • 2014-02-17
      • 2015-08-24
      • 2016-12-16
      • 2013-06-21
      • 2015-06-02
      • 2013-05-23
      相关资源
      最近更新 更多