加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ios – 测试Xcode项目时无法访问AppDelegate

发布时间:2020-12-14 19:08:45 所属栏目:百科 来源:网络整理
导读:参见英文答案 Cannot cast App Delegate to App Delegate in Tests????????????????????????????????????1个 func testExample() { let appDelegate = UIApplication.sharedApplication().delegate as! AppDelegate // some code ...} 上面的函数总是崩溃并
参见英文答案 > Cannot cast App Delegate to App Delegate in Tests????????????????????????????????????1个

func testExample() {
    let appDelegate = UIApplication.sharedApplication().delegate as! AppDelegate
    // some code ...
}

上面的函数总是崩溃并给出这个错误:

Could not cast value of type ‘MyAppName.AppDelegate’ (0x10dc09e80) to ‘MyAppNameTests.AppDelegate’ (0x11cc190c0).

解决方法

您可能正在将AppDelegate编译到测试目标中.不要这样做.

相反,只能编译到您的普通应用目标MyAppName.在你的测试类中写入XCode 7

@testable import MyAppName

在XCode 7之前

import MyAppName

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读