Swift — Require classes implementing protocol to be subclasses of a certain class

前端 未结 8 2018
臣服心动
臣服心动 2021-01-01 08:58

I\'m creating several NSView classes, all of which support a special operation, which we\'ll call transmogrify. At first glance, this seems like t

8条回答
  •  春和景丽
    2021-01-01 09:27

    You could use something like this:

    protocol TransmogrifiableView where Self:NSView {}
    

    This requires all created instances which one conforms to TransmogrifiableView protocol to be subclassed with NSView

提交回复
热议问题