-
Type: Improvement
-
Resolution: Unresolved
-
Priority: Minor - P4
-
None
-
Affects Version/s: None
-
Component/s: None
-
2 - S (<= 1 week)
-
8401
Problem
We are trying to use the 'removeAll' method for a mutable set in a SwiftUI context, if we do for example:
mySet.removeAll()
the app crashes because it is not in a transaction
but if we do
$mySet.removeAll()
removeAll has not been implemented
Solution
could we add another method to this extension:
@available(iOS 13.0, macOS 10.15, tvOS 13.0, watchOS 6.0, *) public extension BoundCollection where Value == MutableSet<Element> { /// :nodoc: func remove(_ element: Value.Element) { write { mutableSet in mutableSet.remove(element) } } /// :nodoc: func insert(_ value: Value.Element) { write { mutableSet in mutableSet.insert(value) } } }
to implement removeAll like insert and remove?
Alternatives
for now we have written an extension on the SwiftUI binding that sets the wrapped value to an empty set:
public extension Binding<MutableSet<String>> { func removeAll() { self.wrappedValue = MutableSet() } }
How important is this improvement for you?
I would like to have it but have a workaround
Feature would mainly be used with
Local Database only