:
, - , .
, :
protocol SomeProtocol {
func hide()
}
, , UIView , , ( ):
class ParentView : UIView, SomeProtocol {
func hide() {
print("PARENT")
}
func anyOtherMethod() {
}
}
UIView, ParentView
:
class ViewOne : ParentView {
override func hide() {
print("VIEW ONE")
}
}
class ViewTwo : ParentView {
override func hide() {
print("VIEW TWO")
}
}
, :
let view = cell.viewWithTag(someTag)
// and I want to write this below without casting
view.hide()
UIView, , , super
EDIT:
, , hide()
, , , UILabel :
class ParentLabel : UILabel, SomeProtocol {
func hide() {
print("PARENT LABEL")
}
}
if let view = cell.viewWithTag(someTag) as? SomeProtocol {
view.hide()
}
UILabel, , , ParentLabel
:
class LabelOne : ParentLabel {
override func hide() {
print("LABEL ONE")
}
}