This is a simplified fragment that doesn't compile for me. How do I fix it?
The version of this code without associated type compiles ok.
// typealias T = Int // this works
protocol Foo: AnyObject {
associatedtype T // this does not work
func foo(_: T) -> T
var value: T { get set }
}
struct Holder {
weak var object: (any Foo)?
}
func bar(holders: [Holder]) {
holders.forEach { holder in
let object = holder.object!
let value = object.foo(object.value) // 🛑 Member 'foo' cannot be used on value of type 'any Foo'; consider using a generic constraint instead
object.value = value
}
}