It seems like I can't give a computed property a default value using the Default Initializers method that can be used for Stored Properties. Here's a use case where I would need this:
@IBDesignable public class MyRoundedCornersView: UIView {
@IBInspectable var cornerRadius: CGFloat {
get {
return self.layer.cornerRadius
}
set {
self.layer.cornerRadius = newValue
}
}
}
I'd like to give the cornerRadius a default value. But the following doesn't work (just added = 8.0
):
@IBDesignable public class MyRoundedCornersView: UIView {
@IBInspectable var cornerRadius: CGFloat = 8.0 {
get {
return self.layer.cornerRadius
}
set {
self.layer.cornerRadius = newValue
}
}
}
I get the not so useful '(() -> () -> $T1) -> $T2' is not identical to 'Double'
error. I looked up here to find out how to do this but it seems Apple doesn't support default values for computed properties. At least I couldn't find anything.
So how can I still make sure that I have a default value for my property? This thread says it isn't possible within the init method either – but even if, I'd like to keep the default value near my property definition. Does anyone have an idea?