0

In ObjC it was possible to define properties like NSObject. How can I do something similar in Swift? I know that there is a way to combine protocols through protocol<A,B,C> but it does not work for types.

rmunn
  • 34,942
  • 10
  • 74
  • 105
Nikita Leonov
  • 5,684
  • 31
  • 37
  • Do you think something like `Any`? It basically means any type that can conform to protocol (that is - not a function). It typealias of `protocol<>`. – Kirsteins Oct 03 '14 at 07:27
  • What I am actually trying to define is a let of AnyObject type that conforms to UITextViewDelegate. Any is too generic, I am trying to be more specific. – Nikita Leonov Oct 03 '14 at 19:08

1 Answers1

0

I guess you are looking for protocol composition, here is an example:

class MyViewController: UIViewController, UITextViewDelegate {

}

var viewController = MyViewController()
var someDelegate: protocol<UITextViewDelegate> = viewController
var backToViewController = someDelegate as MyViewController
Kirsteins
  • 27,065
  • 8
  • 76
  • 78