Swift Array joins EXC_BAD_ACCESS

The Array โ€“join(_:) function returns EXC_BAD_ACCESS.

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

Has anyone encountered this problem? Any solution or suggestion?

enter image description here

+4
arrays join swift
Jul 18 '14 at 8:24
source share
1 answer

Do you want to

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

Usually you use join () to smooth a two-level array by inserting elements from another array 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 the same for strings:

 let ar1 = ["1","2","3"] let res = ".!?".join(ar1) // "1.!?2.!?3" 
+6
Jul 18 '14 at 8:52
source share



All Articles