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<B> { var performWith: (B) -> Void init<T: Proto>(value: T) where T.A == B { self.performWith = value.performWith } } final class SomeType<B> { var protos: [Box<B>] init(_ protos: [Box<B>]) { 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