iOS Questions (Swift Programming Language)
1. What’s the difference between var and let ? Both var and let are references, therefore let is a const reference. let is used to declare a constant value - you won't change it after giving it an initial value. Its a immutable variable. let theAnswer = 42 The theAnswer cannot be changed afterwards. This is why anything weak can't be written using let. They need to change during runtime and you must be using var instead. The var defines an ordinary variable. What is interesting: The value of a constant doesn’t need to be known at compile time, but you must assign the value exactly once. Another strange feature: You can use almost any character you like for constant and variable names, including Unicode characters: let 🐶🐮 = "dogcow" let defines a "constant". Its value is set once and only once, though not necessarily when you declare it. For example, you use let to define a property in a class that must be set during initialization: var is used to dec...
Comments
Post a Comment