[swift-users] Which is the more idiomatic approach for pinning down the type of a generic parameter?
Marco Masser
lists at duckcode.com
Wed Jan 20 07:08:55 CST 2016
> On 2016-01-20, at 13:23, zhaoxin肇鑫 <owenzx at gmail.com> wrote:
>
> Then I think the function with NSButton.self is the best. It makes least efforts for a programmer to get no mistakes.
OK, thank you for your thoughts on this!
I thought I’d mention that I got the idea for dropping the type parameter and shifting that to the caller by reading a blog post by Guille Gonzalez:
https://medium.com/@gonzalezreal/ios-cell-registration-reusing-with-swift-protocol-extensions-and-generics-c5ac4fb5b75e <https://medium.com/@gonzalezreal/ios-cell-registration-reusing-with-swift-protocol-extensions-and-generics-c5ac4fb5b75e>
The very last code snippet in that blog post does exactly that:
let cell: BookCell = collectionView.dequeueReusableCell(forIndexPath: indexPath)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-users/attachments/20160120/b5639d98/attachment.html>
More information about the swift-users
mailing list