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

Code before:
    }
    /// :nodoc:
    @State public var sortDescriptors: [SortDescriptor] = [] {
        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.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
    }

Review comment (suggestion):
```suggestion
             collection.realm?.delete(offsets.compactMap { section[$0].thaw() ?? nil })
```

Code after:
    }
    /// :nodoc:
    @State public var sortDescriptors: [SortDescriptor] = [] {
        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
    }