Error[8]: Undefined offset: 6, File: /www/wwwroot/outofmemory.cn/tmp/plugin_ss_superseo_model_superseo.php, Line: 121
File: /www/wwwroot/outofmemory.cn/tmp/plugin_ss_superseo_model_superseo.php, Line: 473, decode(

概述我有一个符合接口的对象数组 interface SomeInterface{} 和一个符合该接口的类 class SomeClass : NSObject, SomeInterface{} 现在,我创建一个SomeInterface对象数组 var myInterfaceObjects : SomeInterface[] = SomeInterface[]() 然后我想将此数组转换为SomeCla 我有一个符合接口的对象数组

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
解决方法 听起来像编译器错误,你应该报告它(正如凯文在评论中所说)

现在,您可以尝试通过单独转换对象来解决它:

var someClassObjects : [SomeClass] = myInterfaceObjects.map { [+++] as SomeClass }

编辑:更新到最新的swift语法.另外值得一提的是这个BUG可能已在beta 3或beta 4中得到解决 – 我还没有检查过

总结

以上是内存溢出为你收集整理的ios – Swift:从接口类型数组转换为对象数组崩溃全部内容,希望文章能够帮你解决ios – Swift:从接口类型数组转换为对象数组崩溃所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

)
File: /www/wwwroot/outofmemory.cn/tmp/route_read.php, Line: 126, InsideLink()
File: /www/wwwroot/outofmemory.cn/tmp/index.inc.php, Line: 166, include(/www/wwwroot/outofmemory.cn/tmp/route_read.php)
File: /www/wwwroot/outofmemory.cn/index.php, Line: 30, include(/www/wwwroot/outofmemory.cn/tmp/index.inc.php)
ios – Swift:从接口类型数组转换为对象数组崩溃_app_内存溢出

ios – Swift:从接口类型数组转换为对象数组崩溃

ios – Swift:从接口类型数组转换为对象数组崩溃,第1张

概述我有一个符合接口的对象数组 interface SomeInterface{} 和一个符合该接口的类 class SomeClass : NSObject, SomeInterface{} 现在,我创建一个SomeInterface对象数组 var myInterfaceObjects : SomeInterface[] = SomeInterface[]() 然后我想将此数组转换为SomeCla 我有一个符合接口的对象数组

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
解决方法 听起来像编译器错误,你应该报告它(正如凯文在评论中所说)

现在,您可以尝试通过单独转换对象来解决它:

var someClassObjects : [SomeClass] = myInterfaceObjects.map {  as SomeClass }

编辑:更新到最新的swift语法.另外值得一提的是这个BUG可能已在beta 3或beta 4中得到解决 – 我还没有检查过

总结

以上是内存溢出为你收集整理的ios – Swift:从接口类型数组转换为对象数组崩溃全部内容,希望文章能够帮你解决ios – Swift:从接口类型数组转换为对象数组崩溃所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1055447.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-25
下一篇 2022-05-25

发表评论

登录后才能评论

评论列表(0条)

保存