swift - Default implementations for protocols and associated types -


i strange behaviour follow steps of protocol-orientated-programming , default implementations. have protocol, called testprotocol, following implemenation

protocol testprotocol {     init()     func test1()     func test2() } 

and implementation of protocol, called testclass:

struct testclass : testprotocol {     init() {}     func test1() { print("test1") }     func test2() { print("test2") } } 

i want use class in datastructure called datastructure, can take elements of testprotocol. wrote protocol default implementation , implementation:

protocol datastructureprotocol {     typealias elementtype: testprotocol }  extension datastructureprotocol {     func dosomething() {         elementtype().test1()         elementtype().test2()     } }  struct datastructure<t: testprotocol> : datastructureprotocol {     typealias elementtype = t     init() {} } 

i don't know if code complete garbage. if so, please don't hesitate correct me. funny part is, dosomething method doesn't call right methods. prints

test2 test1 

which isn't right order. seems default implementation maps function calls wrong implementations. have no idea why. appreciated.

thanks, rusty1s


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -