使用 RxSwift 和 RxRealm 对成员 'items(cellIdentifier:celltype:)' 的引用不明确
Ambiguous reference to member 'items(cellIdentifier:celltype:)' using RxSwift and RxRealm
我在 ViewController 中有一个 CollectionView,我正在尝试从 Realm 获取对象列表并使用 RxSwift 将其绑定到 CollectionView。
问题是我遇到了错误:
"Ambiguous reference to member 'items(cellIdentifier:celltype:)'"
行中:
.bind(to: collection.rx.items(cellIdentifier ...)
这是代码:
import UIKit
import RxRealm
import RxSwift
import RxCocoa
class MyListViewController: UIViewController {
var myList: MyList?
private var collection: UICollectionView?
{...}
private func loadMyList() {
let myList = retrieveMyListFromDb()
guard
let list = myList,
let collection = collection
else { return }
let disposeBag = DisposeBag()
Observable.from(list)
.bind(
to: collection.rx.items(
cellIdentifier: HomeMovieCollectionViewCell.identifier,
cellType: HomeMovieCollectionViewCell.self)
) { (row, element, cell) in
}
.disposed(by: disposeBag)
}
private func retrieveMyListFromDb() -> MyList? {
return RealmManager().objects(MyList.self)?.filter {
[=11=].userId == 0
}.first
}
这是 MyList 代码:
import Foundation
import Realm
import RealmSwift
@objcMembers
class MyList: Object {
dynamic var userId: Int = 0
var movies = List<Movie>()
public override static func primaryKey() -> String? { return "userId" }
}
感谢用户 Daniel T。我意识到问题在于集合视图的 rx.items 函数需要一个项目数组或列表,而我将它与一个对象一起使用。我遇到的错误根本无法描述正在发生的事情。
解决方案是
Observable.collection(from: list.movies)
.bind(to: collection.rx.items(
cellIdentifier: HomeMovieCollectionViewCell.identifier,
cellType: HomeMovieCollectionViewCell.self)
) { (row, element, cell) in
}
.disposed(by: disposeBag)
我在 ViewController 中有一个 CollectionView,我正在尝试从 Realm 获取对象列表并使用 RxSwift 将其绑定到 CollectionView。
问题是我遇到了错误:
"Ambiguous reference to member 'items(cellIdentifier:celltype:)'"
行中: .bind(to: collection.rx.items(cellIdentifier ...)
这是代码:
import UIKit
import RxRealm
import RxSwift
import RxCocoa
class MyListViewController: UIViewController {
var myList: MyList?
private var collection: UICollectionView?
{...}
private func loadMyList() {
let myList = retrieveMyListFromDb()
guard
let list = myList,
let collection = collection
else { return }
let disposeBag = DisposeBag()
Observable.from(list)
.bind(
to: collection.rx.items(
cellIdentifier: HomeMovieCollectionViewCell.identifier,
cellType: HomeMovieCollectionViewCell.self)
) { (row, element, cell) in
}
.disposed(by: disposeBag)
}
private func retrieveMyListFromDb() -> MyList? {
return RealmManager().objects(MyList.self)?.filter {
[=11=].userId == 0
}.first
}
这是 MyList 代码:
import Foundation
import Realm
import RealmSwift
@objcMembers
class MyList: Object {
dynamic var userId: Int = 0
var movies = List<Movie>()
public override static func primaryKey() -> String? { return "userId" }
}
感谢用户 Daniel T。我意识到问题在于集合视图的 rx.items 函数需要一个项目数组或列表,而我将它与一个对象一起使用。我遇到的错误根本无法描述正在发生的事情。
解决方案是
Observable.collection(from: list.movies)
.bind(to: collection.rx.items(
cellIdentifier: HomeMovieCollectionViewCell.identifier,
cellType: HomeMovieCollectionViewCell.self)
) { (row, element, cell) in
}
.disposed(by: disposeBag)