Generic IBDesginables UIView extension

百般思念 提交于 2019-12-04 19:30:55

extension Foo where ... can only be used if Foo is

  • a generic class or structure
  • a protocol containing some associated types
  • a protocol where we extend with a default implementation for when Self is of a specific (object/reference) type, or conforms to some type constraint.

Trailing 'where' clause for extension of non-generic type 'UIView'

The above error implies that UIView is a non-generic class type, and so where clause cannot be applied here.

So, rather than attempting to extend UIView, you must extend SomeProtocol with a default implementation for cases where Self: UIView

Your extension should extend functionality to all types that conform to SomeProtocol and are of type UIView

In a nutshell, you should switch the order in the extension clause. So,

extension UIView where Self : SomeProtocol

should be

extension SomeProtocol where Self: UIView
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!