Uploaded image for project: 'Realm Cocoa SDK'
  1. Realm Cocoa SDK
  2. RCOCOA-2230

Mutable Set SwiftUI remove all

      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

            Assignee:
            Unassigned Unassigned
            Reporter:
            unitosyncbot Unito Sync Bot
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: