如何正确共享 Realm Result 对象给其他 View?
final class Transaction: Object, ObjectKeyIdentifiable {
@Persisted(primaryKey: true) var _id: ObjectId
@Persisted var buyCurrency = ""
@Persisted var buyAmount = 0
}
struct TransactionView: View {
@ObservedResults(Transaction.self) var transactions
var body: some View {
EditView(transactions: transactions)
}
}
import SwiftUI
import RealmSwift
struct EditView: View {
@ObservedRealmObject var transactions: Results<Transaction>
var body: some View {
...
}
我遇到了这样的编译错误:
通用结构 'ObservedRealmObject' 要求 'Results' 符合 'ObservableObject'