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
.
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.
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()
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With