Error using associated types and generics

后端 未结 3 1219
刺人心
刺人心 2021-02-03 11:55

The following code gives me an error on line return p.foo(self). The error says: \'P\' does not have a member named \'foo\'.

protocol P         


        
3条回答
  •  长发绾君心
    2021-02-03 12:46

    From The Swift Programming Language:

    Protocols do not actually implement any functionality themselves. Nonetheless, any protocol you create will become a fully-fledged type for use in your code.

    In order to use the .foo method, you need a struct or class that implements your protocol.

提交回复
热议问题