RAC和RxSwift

iOS RxDataSources

2019-12-03  本文已影响0人  lczalh

RxDataSource 的本质就是使用 RxSwift 对 UITableView 和 UICollectionView 的数据源做了一层包装

1. UITableView

数据源类型:RxTableViewSectionedReloadDataSourceRxTableViewSectionedAnimatedDataSource

2. UICollectionView

数据源类型:RxTableViewSectionedReloadDataSourceRxCollectionViewSectionedAnimatedDataSource

3. ModelType

模型类型:SectionModelAnimatableSectionModel

4. 使用动画数据源,自定义模型需遵守IdentifiableType协议

class NewsListModel: Object,Mappable {
    @objc dynamic var publishTime: String? // 发布时间
    @objc dynamic var category: String? // 类型
    @objc dynamic var source: String? // 来源
    @objc dynamic var newsId: String? // 新闻ID
    @objc dynamic var title: String? // 标题
    @objc dynamic var newsImg: String? //新闻小图片url

    required convenience init?(map: Map) {
        self.init()
    }

    func mapping(map: Map) {
        publishTime   <- map["publishTime"]
        category   <- map["category"]
        source   <- map["source"]
        newsId   <- map["newsId"]
        title   <- map["title"]
        newsImg   <- map["newsImg"]
    }
}

extension NewsListModel: IdentifiableType {
    var identity: NewsListModel {
    return self
    }

    typealias Identity = NewsListModel
}
上一篇下一篇

猜你喜欢

热点阅读