In-House Articles



Recommended Articles



Jobs



Let's meet in Bangalore

After the great success of Swift Anytime Delhi Meetup, we are excited to bring you the 2nd chapter of Swift Anytime Meetup & this time we are coming to the Silicon Valley Of India - Bangalore.

Register now

🗓 17th Dec 2022 |📍 Bangalore

Thanks to our sponsors Codemagic

Swift Anytime Weekly

Cracking the iOS Interview

What is the difference between classes and structs?

  • The difference between a class and a struct is whether it’s a reference or a value. If you need to store some primitive data types (i.e. ​Ints, ​Floats​, ​Strings, etc.), use a ​struct​.
  • However, if you need custom behaviour where passing by reference is preferred so that you refer to the same instance everywhere, use a class.
  • The other difference is that a ​class ​supports inheritance, while a struct doesn’t.

Note: Basically in Swift, a ​struct ​is preferred over a ​class.

Swift Anytime Weekly

Why should a lazy property be a variable not a constant in Swift?

You must always declare a lazy property as a variable (with the var keyword) because its initial value might not be retrieved until after the instance is initialized. Constant properties must always have a value before the initialization completes, and therefore shouldn’t be declared lazy.

Swift Anytime Weekly

iOS Good Practices

Specify your app’s colors using asset catalogs

It is a little-known feature of Xcode asset catalogs that allows you to add colors directly. Just like images, color literals can be defined and used throughout the app and referred to as images.

The major benefit of using colors in the Assets catalog is that you can define a color in light and dark modes based on your requirements.

This is how you can access the colors defined using assets:

let primaryTextColor = UIColor(named: "PrimaryTextColor")

let secondaryTextColor = UIColor(named: "SecondaryTextColor")

Swift Anytime Weekly

Code Quiz

Which of the following is not true about the lazy property?

  1. You can define a lazy property by lazy var variableName...
  2. It should be used as computationally expensive code.
  3. This value is calculated every time.
  4. Lazy properties are mutable.

Solve the quiz and submit your answer along with your Twitter handle at team@swiftanytime.com

Swift Anytime Weekly

Thanks for Reading

We at Swift Anytime try to bring the best iOS ecosystem information for you that’s not only valuable but also most relevant based on your experience & preference.

Swift Anytime Weekly