这是文件 RxRealm.swift 的顶部部分。 (文件中的其他地方都没有编译错误,也没有“观察”函数。
//
// 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)
}
}
我尝试按照建议添加协议存根,但我不知道添加的观察函数内部有什么内容。
public func observe(on queue: DispatchQueue?, _ block: @escaping (RealmCollectionChange<List<Element>>) -> Void) -> NotificationToken {
// what goes here?
}
我尝试将函数留空,但它会抛出另一个错误:“预期返回‘NotificationToken’(又名‘RLMNotificationToken’)的函数中缺少返回”
如果我放入一个返回函数,我不知道该放什么。显然它是 NotificiationToken 类型,但现在我迷路了。
这确实超出了我的想象,但 Cocoapods 上没有任何相关内容https://cocoapods.org/pods/RxRealm https://cocoapods.org/pods/RxRealm
任何想法如何解决这一问题?
为我工作:
pod 'Realm', '10.20.1'
pod 'RealmSwift', '10.20.1'
pod 'RxRealm', '4.0.3'
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)