Swift动态强制转换失败-尝试运行单元测试时出错 [英] Swift dynamic cast failed - Error when trying to run unit tests

查看:81
本文介绍了Swift动态强制转换失败-尝试运行单元测试时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Xcode版本6.1.1(6A2008a)

Xcode Version 6.1.1 (6A2008a)

错误:libswiftCore.dylib`swift_dynamicCastClassUnconditional 和Swift动态转换失败

Error: libswiftCore.dylib`swift_dynamicCastClassUnconditional and Swift dynamic cast failed

我正在尝试测试,但遇到无法确定如何修复的错误.有人可以说明一下吗?

I am trying to test and I am coming across this error that I am unsure about how to fix. Can someone please shed some light on this?

发生错误:

此强制转换发生错误:

var delegate = UIApplication.sharedApplication().delegate as AppDelegate

阅读这篇文章:我删除了来自测试目标的AppDelegate.swift,但是在构建时出现错误,因为编译器抱怨在转换中不了解"AppDelegate".我很困惑吗?!

After reading this post: I deleted the AppDelegate.swift from the test target but then I get an error when building as the compiler complains about not knowing about "AppDelegate" in the cast. I am confused?!

推荐答案

好吧,在经过一番混乱之后,才解决了该问题:

Ok so after a lot of messing about here is what solved the issue:

  1. 我从应用程序主要(非测试)部分的文件(包括AppDelegate)中删除了所有测试目标成员身份.

  1. 我将需要访问的所有类(在应用程序的主要部分中)(从应用程序的Test部分)更改为公开,并且还将这些类的必需方法也设置为公开) .

  1. I changed all the classes (in the main part of the application) that I needed to access (from the Test part of the application) to be public and also set these class's required methods to be public as well).

我用#import AppName语句

希望能为其他人节省一些时间..:)

Hope that saves some other people some time.. :)

这篇关于Swift动态强制转换失败-尝试运行单元测试时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆