I'm trying to learn UIKit for iOS development and already hit a roadblock in my understanding. In the Apple tutorial on their website they use a UICollectionView.CellRegistration to configure the way a list is displayed, that I understand but the code seems to magically acquire the data type that I set up in another file without me ever explicitly giving it to it. This is the sample they gave on the Apple developer site, but not really an explanation of how it works.
let cellRegistration = UICollectionView.CellRegistration { (cell: UICollectionViewListCell, indexPath: IndexPath, _: String) in
let reminder = Reminder.sampleData[indexPath.item]
var contentConfiguration = cell.defaultContentConfiguration()
contentConfiguration.text = reminder.title
cell.contentConfiguration = contentConfiguration
}
It works and everything, but I'm very confused on where the "cell", "indexPath", and the last String argument come from.
CodePudding user response:
The init method of the registration takes a handler closure (anonymous function) with those arguments, see https://developer.apple.com/documentation/uikit/uicollectionview/cellregistration/3600940-init and here https://developer.apple.com/documentation/uikit/uicollectionview/cellregistration/handler
To find this kind of info out, option click on a symbol in XCode to see it's type and a link to documentation.