Reputation: 1227
I have the following protocol:
protocol TextViewInputField {
var indexPath: IndexPath? { get set }
var textView: UITextView { get set }
var lblPlaceHolder: UILabel { get set }
func updatePHHiddenState()
}
a cell TMStyle2Cell
implements this protocol as follows:
class TMStyle2Cell: UITableViewCell,TextViewInputField {
@IBOutlet var lblPlaceHolder: UILabel!
@IBOutlet var textView: UITextView!
@IBOutlet var viewSeperator: UIView!
var indexPath: IndexPath?
func updatePHHiddenState() {
}
}
Why am I getting the following error?
TMStyle2Cell
does not confirm to protocolTextVeiwInputField
.
Upvotes: 6
Views: 5446
Reputation: 151
Example of protocol. Tested in Swift 4.2.
@objc protocol ImageRepresentable {
var imageView: UIImageView! { get set }
}
And for view.
class ViewA: UIView, ImageRepresentable {
@IBOutlet weak var imageView: UIImageView!
}
For your case.
@objc protocol TextViewInputField {
var indexPath: IndexPath? { get set }
var textView: UITextView! { get set }
var lblPlaceHolder: UILabel! { get set }
func updatePHHiddenState()
}
Upvotes: 9
Reputation: 2367
The types in your protocol and your implementation aren't matching. You need:
protocol TextViewInputField {
var indexPath: IndexPath? { get set }
var textView: UITextView! { get set }
var lblPlaceHolder: UILabel! { get set }
func updatePHHiddenState()
}
If you use weak IBOutlets, you also need to include that:
protocol TextViewInputField {
var indexPath: IndexPath? { get set }
weak var textView: UITextView! { get set }
weak var lblPlaceHolder: UILabel! { get set }
func updatePHHiddenState()
}
Finally, small point, but the set
part of your protocol probably isn't necessary.
Upvotes: 14