简体   繁体   English

XCTest Xcode 7 Beta 3 Swift 2从情节提要发行版启动View Controller

[英]XCTest Xcode 7 beta 3 swift 2 initiate View Controller from storyboard issue

I have this code in XCTest setup 我在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 gives me error "Could not cast value of type" on this line Xcode在此行给我错误“无法转换类型的值”

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

I'm using Swift 2.0 with Xcode 7 beta 3. I tried bundle: 我将Swift 2.0与Xcode 7 beta 3配合使用。

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

I also added the custom view controller class to compile list and Main storyboard to resource of the test target. 我还添加了自定义视图控制器类来编译列表,并将主故事板添加到测试目标的资源。

Any idea? 任何想法? Thanks 谢谢

Instead of making all my custom classes public to the test target. 而不是将所有自定义类公开给测试目标。 I use this new test declaration in swift 2 我在Swift 2中使用了这个新的测试声明

@testable import <my module name>

It works well now. 现在效果很好。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM