I am trying to understand how to properly used NSCoder
when subclassing UIView
:
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
}
I am wondering whether it is possible to access any properties that aDecoder
might carry. I would e.g. expect it to know the size of the frame
that the view has in Storyboards. Is it possible to access this information? I tried the following but it only returned 0-values for the CGRect
:
required init?(coder aDecoder: NSCoder) {
let frame = aDecoder.decodeCGRect(forKey: "frame")
print(frame) // prints: (0.0, 0.0, 0.0, 0.0)
super.init(coder: aDecoder)
}
I checked the documentation of UIView
, but there is no info on this.