Aquí está la parte superior del archivo RxRealm.swift. (En ningún otro lugar del archivo hay errores de compilación ni la función "observar".
// // RxRealm extensions // // Copyright (c) 2016 RxSwiftCommunity. All rights reserved. // Check the LICENSE file for details // Created by Marin Todorov // import Foundation import RealmSwift import RxSwift public enum RxRealmError: Error { case objectDeleted case unknown } // MARK: Realm Collections type extensions /** `NotificationEmitter` is a protocol to allow for Realm's collections to be handled in a generic way. All collections already include a `addNotificationBlock(_:)` method - making them conform to `NotificationEmitter` just makes it easier to add Rx methods to them. The methods of essence in this protocol are `asObservable(...)`, which allow for observing for changes on Realm's collections. */ public protocol NotificationEmitter { associatedtype ElementType: RealmCollectionValue /** Returns a `NotificationToken`, which while retained enables change notifications for the current collection. - returns: `NotificationToken` - retain this value to keep notifications being emitted for the current collection. */ func observe(on queue: DispatchQueue?, _ block: @escaping (RealmCollectionChange<Self>) -> Void) -> NotificationToken func toArray() -> [ElementType] func toAnyCollection() -> AnyRealmCollection<ElementType> } extension List: NotificationEmitter { public func toAnyCollection() -> AnyRealmCollection<Element> { return AnyRealmCollection<Element>(self) } public typealias ElementType = Element public func toArray() -> [Element] { return Array(self) } } extension AnyRealmCollection: NotificationEmitter { public func toAnyCollection() -> AnyRealmCollection<Element> { return AnyRealmCollection<ElementType>(self) } public typealias ElementType = Element public func toArray() -> [Element] { return Array(self) } } extension Results: NotificationEmitter { public func toAnyCollection() -> AnyRealmCollection<Element> { return AnyRealmCollection<ElementType>(self) } public typealias ElementType = Element public func toArray() -> [Element] { return Array(self) } } extension LinkingObjects: NotificationEmitter { public func toAnyCollection() -> AnyRealmCollection<Element> { return AnyRealmCollection<ElementType>(self) } public typealias ElementType = Element public func toArray() -> [Element] { return Array(self) } }Intenté agregar los apéndices de protocolo como se sugiere, pero no sé qué ocurre dentro de la función de observación agregada.
public func observe(on queue: DispatchQueue?, _ block: @escaping (RealmCollectionChange<List<Element>>) -> Void) -> NotificationToken { // what goes here? }Intenté dejar la función en blanco, pero arroja otro error: "Falta el retorno en una función que se espera que devuelva 'NotificationToken' (también conocido como 'RLMNotificationToken')"
Si pongo una función de retorno, no tengo idea de qué poner allí. Obv es el tipo NotificiationToken, pero ahora estoy perdido.
Esto está realmente por encima de mi cabeza, pero no hay nada al respecto en Cocoapods https://cocoapods.org/pods/RxRealm
Alguna idea de cómo solucionar este problema?
trabajando para mi:
pod 'Realm', '10.20.1' pod 'RealmSwift', '10.20.1' pod 'RxRealm', '4.0.3'En Xcode 13.2.1, puede agregar este método, desde la extensión de sugerencia de xcode de Lista, Resultados...
public func observe(on queue: DispatchQueue?, _ block: @escaping (RealmCollectionChange<List<Element>>) -> Void) -> NotificationToken { // what goes here? }--->
public func observe(on queue: DispatchQueue?, _ block: @escaping (RealmCollectionChange<Results<Element>>) -> Void) -> NotificationToken { return self.observe(keyPaths: nil, on: queue, block) }Su problema se resolverá, pero si usa Cocoapods, debe editar directamente el archivo RXRealm en sus pods.
configuración de trabajo
pod 'RxSwift', '~> 5' pod 'RxCocoa', '~> 5' pod 'RxAlamofire', '~> 5.1.0' pod 'RxRealm' pod 'RealmSwift', '10.20.1'