Require type and protocol for method parameter

后端 未结 4 921
猫巷女王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:20

    <> is in Objective-C: conforms to protocol

    <> is in Swift for generics

    You can do more with the where keyword

    Use where after the type name to specify a list of requirements—for example, to require the type to implement a protocol, to require two types to be the same, or to require a class to have a particular superclass.

    Excerpt From: Apple Inc. “The Swift Programming Language.” iBooks.

提交回复
热议问题