Say I have these protocols
protocol Actionable {
}
protocol M: class {
associatedtype Action: Actionable
var views: [Action] { get set }
}
and two functions
func f(view: Actionable) {
}
func g(views: [Actionable]) {
}
And I extend the protocol M
extension M {
func add(view: Action) {
views.append(view)
f(view)
g(views)
}
}
When I call f(view
it works. But when I call g(views)
it shows error
Cannot convert value of type '[Self.Action]' to expected argument type '[Actionable]'
Here g
accepts an array instead of a single object like f
. Why does array matter in this case? How to work around this?
As a side note, this seems to be the kind of error for generic struct, too
protocol Actionable {
}
struct M<T: Actionable> {
var views: [T]
}
func g(views: [Actionable]) {
}
extension M {
func add() {
g(views)
}
}