Repository: realm/realm-swift
File: RealmSwift/SwiftUI.swift (Swift)

Code before:
    public var wrappedValue: SectionedResults<Key, ResultType> {
        storage.setupValue()
        return storage.sectionedResults
    }
    /// :nodoc:
    public var projectedValue: Self {
        return self
    }

    /// Removes items from an `@ObservedSectionedResults` collection
    /// with a given `IndexSet` and `ResultsSection`.
    /// - Parameters:
    ///   - offsets: Index offsets in the section.
    ///   - section: The section containing the items to remove.
    public func remove(atOffsets offsets: IndexSet,
                       section: ResultsSection<Key, ResultType>) where ResultType: ObjectBase & ThreadConfined {
        write(wrappedValue) { collection in
            collection.realm!.delete(offsets.map { section[$0].thaw()! })
        }
    }

    private init(type: ResultType.Type,
                 sectionBlock: @escaping ((ResultType) -> Key),
                 sortDescriptors: [SortDescriptor] = [],
                 filter: NSPredicate? = nil,
                 where: ((Query<ResultType>) -> Query<Bool>)? = nil,
                 keyPaths: [String]? = nil,
                 keyPathString: String? = nil,
                 configuration: Realm.Configuration? = nil) where ResultType: AnyObject {
        let results = Results<ResultType>(RLMResults<ResultType>.emptyDetached())
        self.storage = Storage(results,
                               sectionBlock: sectionBlock,
                               sortDescriptors: sortDescriptors,
                               keyPathString: keyPathString,
                               keyPaths: keyPaths)
        self.storage.configuration = configuration
        if let filter = filter {
            self.filter = filter
        } else if let `where` = `where` {
            self.where = `where`
        }
        self.sortDescriptors = sortDescriptors
    }

    /**
     Initialize a `ObservedSectionedResults` struct for a given `Projection` type.
     - parameter type: Observed type
     - parameter sectionKeyPath: The keyPath that will produce the key for each section.
     For every unique value retrieved from the keyPath a section key will be generated.
     - parameter sortDescriptors: A sequence of `SortDescriptor`s to sort by.
     - parameter filter: Observations will be made only for passing objects.

Review comment (suggestion):
We could also add an append function, something like this
```
public func append(_ value: Value.Element.Element) where Value.Element.Element: Object {
        write(wrappedValue) { collection in
            collection.realm!.add(value)
        }
}
```

Code after:
        willSet {
            storage.sortDescriptors = newValue
        }
    }
    /// :nodoc:
    public var wrappedValue: SectionedResults<Key, ResultType> {
        storage.setupValue()
        return storage.sectionedResults
    }
    /// :nodoc:
    public var projectedValue: Self {
        return self
    }

    /// Removes items from an `@ObservedSectionedResults` collection
    /// with a given `IndexSet` and `ResultsSection`.
    /// - Parameters:
    ///   - offsets: Index offsets in the section.
    ///   - section: The section containing the items to remove.
    public func remove(atOffsets offsets: IndexSet,
                       section: ResultsSection<Key, ResultType>) where ResultType: ObjectBase & ThreadConfined {
        write(wrappedValue) { collection in
            collection.realm?.delete(offsets.compactMap { section[$0].thaw() ?? nil })
        }
    }

    private init(type: ResultType.Type,
                 sectionBlock: @escaping ((ResultType) -> Key),
                 sortDescriptors: [SortDescriptor] = [],
                 filter: NSPredicate? = nil,
                 where: ((Query<ResultType>) -> Query<Bool>)? = nil,
                 keyPaths: [String]? = nil,
                 keyPathString: String? = nil,
                 configuration: Realm.Configuration? = nil) where ResultType: AnyObject {
        let results = Results<ResultType>(RLMResults<ResultType>.emptyDetached())
        self.storage = Storage(results,
                               sectionBlock: sectionBlock,
                               sortDescriptors: sortDescriptors,
                               keyPathString: keyPathString,
                               keyPaths: keyPaths)
        self.storage.configuration = configuration
        if let filter = filter {
            self.filter = filter
        } else if let `where` = `where` {
            self.where = `where`
        }
        self.sortDescriptors = sortDescriptors
    }

    /**
     Initialize a `ObservedSectionedResults` struct for a given `Projection` type.