I have the following 3 classes in my app:
Class 1.
@IBDesignable final class VerticalCarouselView: UIView {
@objc var font: UIFont = .systemFont(ofSize: 18, weight: .semibold)
@IBInspectable var textColor: UIColor = .black
@objc var textAlignment: NSTextAlignment = .center
...
}
Class 2.
@IBDesignable final class CircleView: UIView {
@IBInspectable var circleForegroundColor: UIColor = .white
@IBInspectable var circleBackgroundColor: UIColor = .black
...
}
Class 3.
@IBDesignable final class FlowerView: UIView {
@IBInspectable var flowerFillColor: UIColor = .white
@IBInspectable var flowerBorderColor: UIColor = .black
@IBInspectable var flowerPetalFillImage: UIImage?
@IBInspectable var flowerPetalBorderImage: UIImage?
...
}
All properties included in the listings above are being observed using NSKeyValueObservation
. Everything works great but as soon as I remove @objc
from font
and textAlignment
in VerticalCarouselView
shown above, the app crashes with Could not extract a String from KeyPath ...
error message.
So my question is, why does the font
and the textAlignment
properties need @objc
while the other ones work without problems?