Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Add non-updating insert methods to swift Set
import Foundation
extension Set {
mutating func nonUpdatingInsert(member: Element) {
if !self.contains(member) {
mutating func nonUpdatingUnionInPlace<S : SequenceType where S.Generator.Element == Element>(sequence: S) {
for item in sequence {
if !self.contains(item) {

This comment has been minimized.

Copy link
Owner Author

commented Jan 8, 2016

Official insert method is actually an upsert. See
This is a quick fix for those who want a non updating version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.