Skip to content

Instantly share code, notes, and snippets.

@b3ll
Last active July 22, 2016 18:15
Show Gist options
  • Select an option

  • Save b3ll/7fa7f5515cb9170b296fd6e75726678c to your computer and use it in GitHub Desktop.

Select an option

Save b3ll/7fa7f5515cb9170b296fd6e75726678c to your computer and use it in GitHub Desktop.
Sadface
//: Playground - noun: a place where people can play
import UIKit
protocol Item {
var title: String? { get set }
var value: String? { get set }
}
protocol ItemContainerViewDelegate {
func itemContainerView<T: Item>(itemContainerView: ItemContainerView<T>, didSelectItem item: T?)
}
class ItemContainerView<T: Item>: UIView {
var delegate: ItemContainerViewDelegate?
func onTap() {
// error: cannot convert value of type ItemContainerView<T> to expected argument type ItemContainerView<_>
delegate?.itemContainerView(self, didSelectItem: nil)
}
}
@b3ll

b3ll commented Jul 22, 2016

Copy link
Copy Markdown
Author

@NachoSoto well the cocoa way to do delegates is to pass back the original object that's firing the delegate, so without that it's not as useful. i.e. tableView:deselectRowAtIndexPath:animated:. I suppose I could pass back the index of the object, but that wouldn't be as nice than the object itself.

I'm not sure if type erasure is possible at this point, anything other than this I've tried has just lead to the compiler complaining about associatedtype dependencies :/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment