Created
October 29, 2017 19:32
-
-
Save tid-kijyun/6a5c4b96de80cecd51314ba9e09a8748 to your computer and use it in GitHub Desktop.
RxSwift + RxRealmで複数セクションに対応したDataSourceを作ってみたけどまだ欲しいものになってない感じ #CodePiece
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Section: Object, RealmSectionModelType { | |
public typealias Item = RowItem | |
public let item = List<Item>() | |
@objc dynamic var title = "" | |
} | |
public class RowItem: Object { | |
@objc dynamic var title = "" | |
} | |
class ViewController: UIViewController { | |
@IBOutlet weak var tableView: UITableView! | |
let realm = try! Realm() | |
override func viewDidLoad() { | |
let realmSectionedDataSource = RxRealmSectionedDataSources<Section>(configureCell: { ds, tableView, indexPath, item in | |
//... | |
cell.title.text = item.title | |
}) | |
realmSectionedDataSource.titleForHeaderInSection = { tv, section in | |
return realmSectionedDataSource.sectionsModel?[section].title | |
} | |
Observable.sectionedChangeset(from: realm.objects(Section.self)) | |
.bind(to: tableView.rx.items(dataSource: realmSectionedDataSource)) | |
.disposed(by: disposeBag) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment