本文介绍了斯威夫特加盟阵列EXC_BAD_ACCESS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

阵列 -join(_:)函数抛出一个EXC_BAD_ACCESS

Array –join(_:) function throws an EXC_BAD_ACCESS.

var ar1 = [1,2,3]
var ar2 = [5,6,7]
var res = ar1.join(ar2)

有没有人遇到这个问题?任何解决方案或建议?

Has anyone faced this problem? Any solution or suggestion?

推荐答案

您需要的是

var ar1 = [1,2,3]
var ar2 = [5,6,7]
var res = ar1 + ar2

您通常会通过插入另一个数组中的元素在第一级别的元素之间使用join()方法扁平化两级数组:

You would usually use join() to flatten a two level array by inserting the elements from another array in between first level elements:

var ar1 = [1,2,3]
var ar2 = [[4,5,6],[7,8,9],[10,11,12]]
let res = ar1.join(ar2) // [4, 5, 6, 1, 2, 3, 7, 8, 9, 1, 2, 3, 10, 11, 12]

该函数以相同的方式适用于字符串也

The function works in the same fashion for strings also:

let ar1 = ["1","2","3"]
let res = ".!?".join(ar1) // "1.!?2.!?3"

这篇关于斯威夫特加盟阵列EXC_BAD_ACCESS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-19 22:22