[swift-users] how to create an array by adding/removing from another array?

Jens Alfke jens at mooseyard.com
Wed Aug 24 10:50:09 CDT 2016


> On Aug 24, 2016, at 7:07 AM, Jean-Denis Muys via swift-users <swift-users at swift.org> wrote:
> 
> However I was wondering if it was possible (preferable?) to do it in a more “functional” style.

Apple’s Foundation framework has Array.arrayByAddingObject (but not ByRemoving).

However, this would not be preferable (at least in performance) due to all the copying. Performance of appending n items would be O(n^2), for instance, vs. O(n) for appending in-place.

—Jens
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-users/attachments/20160824/235d4dc0/attachment.html>


More information about the swift-users mailing list