Require type and protocol for method parameter

后端 未结 4 920
猫巷女王i
猫巷女王i 2020-12-29 04:11

I am playing around with Swift and am stumbling over the following problem: given I have the predefined class Animal:

//Predefined classes
class         


        
4条回答
  •  执笔经年
    2020-12-29 04:41

    Swift 3 version

    In Swift 3 the structure changed a bit. That´s why you will get a deprecation warning for the old structure. Here´s the new one:

    For functions the expected protocols are located after the parameters definition of the function. Example:

    func addAnimal(animal: T) where T: Nameable
    

    For enums or classes the structure also changed

    enum ZooEnum where T: Nameable 
    
    class Zoo where T: Nameable 
    

提交回复
热议问题