Swift中的_ArrayBuffer是什么?何时以及何时使用它? [英] what is `_ArrayBuffer` in Swift and how and when I should to use it?

查看:106
本文介绍了Swift中的_ArrayBuffer是什么?何时以及何时使用它?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用崩溃消息调试崩溃时,线程1:致命错误:NSArray元素与Swift Array元素类型不匹配。我将列表传递给函数: [MyObject] ,但是Xcode的调试窗口区域中的调试器向我显示:

When debugging a crash with crash message Thread 1: Fatal error: NSArray element failed to match the Swift Array Element type. I passing a list to a function: [MyObject] but the debugger in debug window area of Xcode show me:

list([Project.MyObject])
  _buffer (_ArrayBuffer<Project.MyObject>)
     _storage(_ArrayBridgeStorage)
       rawValue = (Bultin.BridgeObject)

更新:
MyObject 来自 XCTestCase 类。我将创建 MyObject 列表的方法移到我的逻辑类中。测试为成功。因此,我确定崩溃与可可臭虫有关。但是仍然不知道如何解决它。

Update: Instate of create and passing list of MyObject from XCTestCase class. I move the method which create list of MyObject into my logic class. The test is Success. So I am sure the crash relate to cocoa bug. But still don't know how to work around to fix it.

推荐答案

崩溃与<$ c无关$ c> _ArrayBuffer 是。发生崩溃是因为您从Cocoa / Objective-C获得了一个NSArray,该数组中期望有一个MyObject数组,而NSArray中的某个东西不是一个MyObject。

The crash has nothing to do with what _ArrayBuffer is. The crash is because you obtained an NSArray from Cocoa / Objective-C where an array of MyObject was expected, and something in the NSArray was not a MyObject.

这确实一次又一次地发生,主要是因为可可本身存在错误。 (我在这里举个例子: UIDynamicAnimator项目(in :)在iOS 11中崩溃。)不幸的是,您根本没有显示您的代码,因此在您的情况下它如何发生是任何人的猜测。

That does happen now and again, mostly because of bugs in Cocoa itself. (I give an example here: UIDynamicAnimator items(in:) crashes in iOS 11.) Unfortunately you showed no code of yours at all, so how it happened in your case is anyone's guess.

这篇关于Swift中的_ArrayBuffer是什么?何时以及何时使用它?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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