我有一个符合接口的对象数组
interface SomeInterface{}
和一个符合该接口的类
class SomeClass : NSObject,SomeInterface{}
现在,我创建一个SomeInterface对象数组
var myInterfaceObjects : SomeInterface[] = SomeInterface[]()
然后我想将此数组转换为SomeClass对象数组
var someClassObjects : SomeClass[] = myInterfaceObjects as SomeClass[] //CRASH!
我如何在没有崩溃的情况下垂头丧气?
Fatal error: can't reinterpretCast values of different sizes (lldb) bt * thread #1: tid = 0x935ef,0x001986b8 libswift_stdlib_core.dylib`Swift.reinterpretCast <A,B>(A) -> B + 220,queue = 'com.apple.main-thread',stop reason = EXC_BREAKPOINT (code=EXC_ARM_BREAKPOINT,subcode=0xe7ffdefe) * frame #0: 0x001986b8 libswift_stdlib_core.dylib`Swift.reinterpretCast <A,B>(A) -> B + 220 frame #1: 0x001bebdc libswift_stdlib_core.dylib`Swift.ContiguousArrayBuffer.storesOnlyElementsOfType <A>(Swift.ContiguousArrayBuffer<A>)<B>(B.Type) -> Swift.Bool + 912 frame #2: 0x001bde08 libswift_stdlib_core.dylib`Swift._arrayCheckedDownCast <A,B>(Swift.Array<A>) -> Swift.Optional<Swift.Array<B>> + 292 frame #3: 0x00094c84 MyApp`MyApp.MyClass.(data=SomeInterface[]! at 0x27db0870,response=Foundation.NSHTTPURLResponse! at 0x27db086c,error=None,self=<unavailable>) -> (Swift.Bool) -> ()).(closure #1) + 428 at MyClass.swift:81
解决方法
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。