Having trouble understanding the closure in UICollectionViewDiffableDataSource
, particularly what's being passed into it. All of the tutorials I can find explain what to type but not why, and I'm still a bit new to Swift and programming.
I'm following along with Paul Hudson's tutorial (he's making an app store made up of App
objects) and in createDataSource()
he writes:
dataSource = UICollectionViewDiffableDataSource<Section, App>(collectionView: collectionView)
{ collectionView, indexPath, app in
//rest of the closure
}
My confusion on the closure's parameters is about where they're coming from:
- He happens to declare
collectionView
as a global variable elsewhere in the View Controller. So I suppose that's required for this to be passed in? - Where is
indexPath
coming from here? - Most confusing: how does it know what
app
is? As far as I can tell it's not declared anywhere. This is the case in all the tutorials I've seen. Where in the world is the concept of an instance ofApp
coming from?
Thank you a ton to anyone who can help me grasp this, I've been scouring tutorials but its been tough to figure out the mechanics here.