Swift Questions and References

In February, I joined a new start-up to help them build a mobile app for Food market. When I was onboarded, I was assigned to an existing iOS project using Swift. In this post, I noted all the questions and references I found during the time I was adapting to that project.

1. What is the “required init” decoder?

https://medium.com/@CoderLyn/swift-required-init-decoder-b3aa829b4acf

https://stackoverflow.com/questions/38386339/what-exactly-is-init-coder-adecoder

https://stackoverflow.com/questions/52239550/when-is-required-initcoder-adecoder-nscoder-called-on-a-uiview-or-uiviewco

2. What is the difference between let and var in Swift?

Source: Stackoverflow

The let keyword defines a constant:

let theAnswer = 42

The theAnswer cannot be changed afterward. 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"

3. What is optional in Swift?

https://drewag.me/posts/2014/07/05/what-is-an-optional-in-swift#optional-binding

Tagged : / /