Here's the top portion of the file RxRealm.swift. (nowhere else in the file are there compile errors nor the "observe" func.
//
// 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)
}
}
I've tried adding the protocol stubs as suggested but I don't know what goes inside the added observe function.
public func observe(on queue: DispatchQueue?, _ block: @escaping (RealmCollectionChange<List<Element>>) -> Void) -> NotificationToken {
// what goes here?
}
I've tried leaving the function blank but it spits out another error: "Missing return in a function expected to return 'NotificationToken' (aka 'RLMNotificationToken')"
If I put in a return function I have no idea what to put in there. Obv it's the NotificiationToken type, but now I'm lost.
This is really above my head, but there's nothing about it on Cocoapods https://cocoapods.org/pods/RxRealm
Any ideas how to fix this?
working for me:
pod 'Realm', '10.20.1'
pod 'RealmSwift', '10.20.1'
pod 'RxRealm', '4.0.3'
In Xcode 13.2.1, you can add this method, from xcode suggestion extension of List, Results...
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)
}
Your problem will be resolve, but if you using Cocoapods, you must directly edit RXRealm file in your pods.
working config.
pod 'RxSwift', '~> 5'
pod 'RxCocoa', '~> 5'
pod 'RxAlamofire', '~> 5.1.0'
pod 'RxRealm'
pod 'RealmSwift', '10.20.1'