How do I make a exact duplicate copy of an array?

前端 未结 5 1435
一向
一向 2020-11-27 13:24

How would I make an exact duplicate of an array?

I am having hard time finding information about duplicating an array in Swift.

I tried using .copy()

5条回答
  •  無奈伤痛
    2020-11-27 14:09

    Nate is correct. If you are working with primitive arrays all you need to do is assign duplicateArray to the originalArray.

    For the sake of completeness, if you were working an NSArray object, you would do the following to do a full copy of an NSArray:

    var originalArray = [1, 2, 3, 4] as NSArray
    
    var duplicateArray = NSArray(array:originalArray, copyItems: true)
    

提交回复
热议问题