Skip to content

Instantly share code, notes, and snippets.

@ivanlesko
Created October 30, 2015 18:50
Show Gist options
  • Save ivanlesko/e86d55d4bf6b3f4122e0 to your computer and use it in GitHub Desktop.
Save ivanlesko/e86d55d4bf6b3f4122e0 to your computer and use it in GitHub Desktop.
// From: http://stackoverflow.com/a/30724543/2526115
// Adds the ability to remove a certain object based on value from an array
extension RangeReplaceableCollectionType where Generator.Element : Equatable {
// Remove first collection element that is equal to the given `object`:
mutating func removeObject(object : Generator.Element) {
if let index = self.indexOf(object) {
self.removeAtIndex(index)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment