Reputation: 91
In appears that in Swift you cannot create an IBOutlet that conforms to a protocol. My current work around is creating an IBOutlet of type AnyObject and a variable that conforms to my protocol and then setting said variable to the outlet in awakeFromNib() like so:
@IBOutlet private var fooOutlet: AnyObject!
private var foo: FooProtocol!
override func awakeFromNib() {
super.awakeFromNib()
foo = fooOutlet as? FooProtocol
}
My question is: Is there a better way to accomplish this ? or is this the only way that this can be accomplished in Swift?
Upvotes: 3
Views: 302