Jon889
(Jonathan Bailey)
1
It would be really great if you could specify that a generic type might conform to a type.
Eg:
protocol LogOutDelegate {
func logOutPressed()
}
class AccountView<T: DetailsDelegate? & LogOutDelegate?> {
var delegate: T
func logOut() {
delegate.logOutPressed?()
}
}
(That was types directly in so forgive any errors)
At the moment I have different delegate variables (eg logOutDelegate detailsDelegate and it would be great to combine them into one.
timv
(Tim Vermeulen)
2
You could perhaps do something like
extension AccountView where T: LogOutDelegate {
func logOut() {
delegate?.logOutPressed()
}
}
And if you always want the logOut function to be available, you could also consider implement it with
(delegate as? LogOutDelegate)?.logOutPressed()
jrose
(Jordan Rose)
3
1 Like