I have @IBOutlet var heading of type UILabel in base class, now I subclassed this and in the new class I want to have @IBoutlet heading of type MyLabel
(let's say I have a class MyLabel
subclassed from UILabel). So the question is: how to override the same property to different compatible class?
Asked
Active
Viewed 606 times
1

Eric Aya
- 69,473
- 35
- 181
- 253

Ajay Kumar
- 1,807
- 18
- 27
-
you can cast it as `MyLabel` if is a subclass and your IBOutlet class in storyboard is correct you can't have any problems – Reinier Melian Feb 15 '18 at 12:09
-
1Goto storyboard select label - > set class to MyLabel -> Connect IBOutlet you done – Prashant Tukadiya Feb 15 '18 at 12:11
-
https://stackoverflow.com/questions/24094158/overriding-superclass-property-with-different-type-in-swift This can help. – Fauad Anwar Feb 15 '18 at 12:15
1 Answers
0
There is no way to override property with different type. You can change a class of this property in the Interface Builder and make another property with needed class:
@IBOutlet override var label: UILabel!
private var myLabel: MyLabel? {
return label as? MyLabel
}

Ilya Kharabet
- 4,203
- 3
- 15
- 29