iOS RxDataSources

作者: lczalh | 来源:发表于2019-12-03 09:32 被阅读0次

    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
    }
    

    相关文章

      网友评论

        本文标题:iOS RxDataSources

        本文链接:https://www.haomeiwen.com/subject/gcaqgctx.html