Hello. What if in a big projects associated type in protocols has identical name for a common functionality like a Player? For illustration I attach a code example.
protocol Additional {
func add()
}
protocol Substractable {
func subatract()
}
protocol A {
associatedtype Player: Additional
var one: Player { get }
}
protocol B {
associatedtype Player: Substractable
var two: Player { get }
}
func checkAssociatedName<T>(a: T) where T: A, T: B {
let b = a.one // T.Player
b.add()
b.subatract() // b is type of A.Player which does not have method 'subatract'... or not?
}
struct Implementation {
struct LittleAlien: Additional {
func add() {}
}
struct Gnome: Substractable {
func subatract() {}
}
struct Bee: A, B {
typealias Player = <#type#> // Which type here I should write?
let one = LittleAlien()
let two = Gnome()
}
func run() {
let bee = Bee()
checkAssociatedName(a: <#A & B#>) // I want to insert my bee here
}
}
Need to look for different names? And sweep associatedtype Player
to Person
, looking for synonyms?