InterviewSolution
Saved Bookmarks
| 1. |
In the given code snippet, we have used var to declare viewOne and let to create viewTwo. Will the last line compile? |
|
Answer» import UIKitvar viewOne = UIView()viewOne.alpha = 0.7let viewTwo = UIView()viewTwo.alpha = 0.7 // Does this line COMPILE? The last line will, in fact, compile. viewOne is a variable that we can reassign to a new UIView object. Because we can only assign a value once with let, the FOLLOWING code will not compile: viewTwo = viewOne // Error: viewTwo is immutableHowever, because UIView is a reference-based CLASS, we can change the properties of viewTwo — which means the following code will compile: let viewTwo = UIView()viewTwo.alpha = 0.7 // Yes, this COMPILES! |
|