Skip to content
Snippets Groups Projects
Commit 418d6da8 authored by Tobias Ullerich's avatar Tobias Ullerich
Browse files

Add remove item method to array

parent 1fb393dd
Branches
No related tags found
No related merge requests found
......@@ -21,4 +21,22 @@ public extension Array where Element: Equatable
}
return secondArrayCopy.isEmpty
}
@discardableResult mutating func remove(item: Element) -> Bool {
if let index = firstIndex(of: item) {
self.remove(at: index)
return true
}
return false
}
@discardableResult mutating func remove(where predicate: (Array.Iterator.Element) -> Bool) -> Bool {
if let index = self.firstIndex(where: { (element) -> Bool in
return predicate(element)
}) {
self.remove(at: index)
return true
}
return false
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment