Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clarity on init with Self requirement of SectionModelType in RxDataSources #360

Open
lukya opened this issue Mar 19, 2020 · 1 comment
Open

Comments

@lukya
Copy link

lukya commented Mar 19, 2020

I posted this on StackOverflow first, but I assume, this community should be able to help me better / faster in this case.

Binding a sectioned table with RxDataSources using a TableViewSectionedDataSource, requires sections which conform to SectionModelType.

This SectionModelType protocol has the following initializer as one of it's requirements:

    init(original: Self, items: [Item])

In addition, the same protocol enforces var items: [Item] { get }. We can now initialize the items array backing variable (in above mentioned init) with either from original.items, or items passed as init parameter. This is very confusing. The SectionModelType code has no comments.

How section of README which explains creation of sections for this very case, talks about creating typealias (for associated value), and the items array, but not a word about following implementation of init with original: Self :

init(original: SectionOfCustomData, items: [Item]) {
    self = original
    self.items = items
}

While this can work in a struct, doing the same in a class shouts:

Cannot assign to value: 'self' is immutable

Can anyone here explain what is happening here and why do we NEED to init with Self

Lastly, is there another (cleaner) way to reactively (in RXSwift / RxCocoa only) bind a sectioned table view to an observable datasource.
e.g.

  • my cells, and sections have their own data model, which need to be mutable (hence classes)
  • there are multiple screens with this requirement for different entities, so i would be interesetd in achieving this with protocols instead, and slap the corresponding data model with the protocol ans have a common implementation for RXBinding

Any pointers to either get clarity more on existing implementation, or achieving above points would be really helpful.

@iadcialim
Copy link

I have this problem now. I need to add a new mutating field in my SectionModel.
@lukya Do you have a workaround?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants