Skip to content

Instantly share code, notes, and snippets.

@tid-kijyun
Created October 29, 2017 19:32
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tid-kijyun/6a5c4b96de80cecd51314ba9e09a8748 to your computer and use it in GitHub Desktop.
Save tid-kijyun/6a5c4b96de80cecd51314ba9e09a8748 to your computer and use it in GitHub Desktop.
RxSwift + RxRealmで複数セクションに対応したDataSourceを作ってみたけどまだ欲しいものになってない感じ #CodePiece
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