Last active
March 10, 2022 08:10
-
-
Save kristopherjohnson/b8c7a88e33c6803408e27e43347bc1f4 to your computer and use it in GitHub Desktop.
Swift 3: Create new array by appending an element to existing array
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension Array { | |
/// Returns a new `Array` made by appending a given element to the `Array`. | |
func appending(_ newElement: Element) -> Array { | |
var a = Array(self) | |
a.append(newElement) | |
return a | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment