UIKit ListsOfState Case Study: Why the local dataSource var in the ViewController? #351
-
I've just been looking through the UIKit case studies, and I noticed that the Why is that? Is there a particular reason? At first glance, it just looks like a way to call |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 5 replies
-
Hey @ryanbooker, the And the label for the cell at a particular row: To me it seems necessary to implement the data source protocol. Could you explain a bit more about how it's trivial to remove? I may be missing something. |
Beta Was this translation helpful? Give feedback.
-
I also want to ask @brandon Williams <mbw234@gmail.com> about the best
approach to take to have a viewStore for each cell on UIKit.
having a setter like: cell.viewStore = viewStore is an ultimate solution ?
Thanks for taking time for this.
…On Tue, 26 Jan 2021 at 11:12, Ryan Booker ***@***.***> wrote:
I think my question boils down to, why not:
self.viewStore.publisher.counters
.sink(receiveValue: { [weak self] _ in self?.tableView.reloadData() })
.store(in: &self.cancellables)
and in the UITableViewDataSource
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
self.viewStore.counters.count
}
and
cell.textLabel?.text = "\(self.viewStore.counters[indexPath.row].count)"
I could be missing something too… I'm still getting my head around all
this. :)
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#351 (reply in thread)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ADDCYOHXBXDUFXLTXAD6APLS32ISRANCNFSM4WFEEBUA>
.
|
Beta Was this translation helpful? Give feedback.
-
Thanks Brandon.
…On Tue, 26 Jan 2021 at 15:49, Brandon Williams ***@***.***> wrote:
Yeah that seems fine to me. It might also be possible to cook up a
Store.forEach operator that mimics the ForEachStore view in SwiftUI (we
already have Store.ifLet that mimics IfLetStore), which would allow you
to pass a Store to each cell and then turn it into a ViewStore inside the
cell. But we haven't given much thought to that yet.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#351 (reply in thread)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ADDCYOCBZKZUJEL7R6IZVOTS33JA5ANCNFSM4WFEEBUA>
.
|
Beta Was this translation helpful? Give feedback.
Hey @ryanbooker, the
dataSource
variable is what powers theUITableViewDataSource
conformance. For example, it determines the number of rows in the table view:swift-composable-architecture/Examples/CaseStudies/UIKitCaseStudies/ListsOfState.swift
Lines 56 to 58 in 11f215c
And the label for the cell at a particular row:
swift-composable-architecture/Examples/CaseStudies/UIKitCaseStudies/ListsOfState.swift
Line 65 in 11f215c
To me it seems necessary to implement th…