0

I would like to gain a new array by appending elements to an existing array without modifying it. NSArray has arrayByAddingObjectsFromArray(), e.g.:

let numbers = (["one", "two", "three"] as NSArray).arrayByAddingObjectsFromArray(["four", "five"]) as! [String]

Is there an equivalent for Swift's Array struct that would make bridging to NSArray unnecessary?

Lars Blumberg
  • 16,724
  • 10
  • 81
  • 114

1 Answers1

4

Do you looking for this one? Your existing array does not modify.

let existingArray = ["four", "five"]
let numbers = ["one", "two", "three"] + existingArray
Muzahid
  • 4,702
  • 2
  • 22
  • 36