Thanks, that works party as needed but I just realize this main idea here is
exactly an example where one would need generic protocols, because I cannot
overload the function with associatedtype as I’d need it.
--
Adrian Zubarev
Sent with Airmail
Am 2. Dezember 2016 um 13:33:37, Tino Heth (2...@gmx.de) schrieb:
Any advice how to rewrite the code so it still would do its job under the hood?
I'm not aware of any clean way to do this (with current Swift ;-) — but this
hack passes compilation:
protocol Proto : class {
// `A` is a generic type and therefore should stay as an associatedtype
associatedtype A
func performWith(_ a: A)
}
struct Box {
var performWith: (B) -> Void
init(value: T) where T.A == B {
self.performWith = value.performWith
}
}
final class SomeType {
var protos: [Box]
init(_ protos: [Box]) {
self.protos = protos
}
func callProtosWith(_ b: B) {
self.protos.forEach {
$0.performWith(b)
}
}
}
___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users