Chun Wing Lean Chun Wing Lean - 6 months ago 47
Swift Question

How to merge two nsmutablearray together (Swift)

How to merge two nsmutablearray together or how to merge nsmutablearray to a NSArray?

i tried to merge two array with "+" but it fails. please help. thank you.

Answer

You can merge 2 NSMutableArrays like this

var array1:NSMutableArray = NSMutableArray(array: [1,2,3])
var array2:NSMutableArray = NSMutableArray(array: [2,3,4])

var mergedArray = array1.arrayByAddingObjectsFromArray(array2 as [AnyObject])