Technical Articles
#SwiftSugar: computed initial values with didSet()
We all know didSet() is not called when initializing a property, and we know we can compute an initial value in a closure.
Put them together, and what do you get?
/// The width of the view's top border line. /// /// Defaults to `2 / UIScreen.main.scale` public var topBorderWeight: CGFloat = { 2 / UIScreen.main.scale }() { didSet { setNeedsDisplay() } }
Be the first to leave a comment
You must be Logged on to comment or reply to a post.