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
  • 19,326
  • 11
  • 90
  • 127

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
  • 5,072
  • 2
  • 24
  • 42