Created
January 8, 2016 13:19
-
-
Save simonracz/fa2b9267ce07278d926d to your computer and use it in GitHub Desktop.
Add non-updating insert methods to swift Set
This file contains hidden or 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
import Foundation | |
extension Set { | |
mutating func nonUpdatingInsert(member: Element) { | |
if !self.contains(member) { | |
self.insert(member) | |
} | |
} | |
mutating func nonUpdatingUnionInPlace<S : SequenceType where S.Generator.Element == Element>(sequence: S) { | |
for item in sequence { | |
if !self.contains(item) { | |
self.insert(item) | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Official insert method is actually an upsert. See http://www.chaonis.com/2016/01/swift-set-vs-nsmutableset/
This is a quick fix for those who want a non updating version.