I am making a demo for learning how @IBInspectable works.
First, I made two variables in UIViewController subclass:
@IBInspectable var intTest:Int = 10
@IBInspectable var flag:Bool = false
So that it appears in the storyboard. After that, I change the value of those variables in the storyboard:
Then, I try to print those variables in "viewDidLoad()" method like this:
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
print("intTest value: \(String(describing: intTest))")
print("flag value: \(String(describing: flag)))")
}
The output is:
intTest value: 90
flag value: true
It works fine, except when I change the variables declaration like,
@IBInspectable var intTest:Int? = 10
@IBInspectable var flag:Bool? = false
After that, I changed the value same as above in the storyboard, but the values are not changed.
Output is:
intTest value: Optional(10)
flag value: Optional(false)
So my question is, why is the value not updated when i declare the variable as optional?
The another thing is, when I take the variable as a string the value is updated. Can anyone help me understand this functionality?