Chapter 7 - Swift Optionals

in #swift6 years ago
  • Swift is a very safe language. It works hard to ensure your code never fails in surprising ways.
  • Optionals are a powerful feature in Swift language which come to solve the problem of non-existing values. Optionals are a powerful feature in Swift language which come to solve the problem of non-existing values.
  • An optional represents two possibilities: Either there is a value, and you can unwrap the optional to access that value, or there isn’t a value at all.

Swift Tutorials Priya Talreja

  • The question mark indicates that the value it contains is optional, meaning that it might contain some Int value, or it might contain no value at all.
  • The Exclamation mark (!) indicates that we are sure that the variable contains some value. It is called force unwrapping.
  • A good practice is to check for nil before unwrapping.

My next blog will be on Types of Data.

Priya Talreja Xcode Tutorials
Please let me know if you have any doubts or queries in the comment section below.
Follow me @priyatalreja to get the latest feeds of iOS App step by step development tutorials.
Thanks.