Learning is a gradual process, and it is difficult to start with everything. Swift says it's easy to get started, but there's a little bit of knowledge that you can learn and practice to understand.
Need to practise a IoT and test what's optiontal Type and how to use it very well
Optional Introduction:
An optional value either contains a value or contains nil (no value) to indicate, a value is missing. Write a question mark (?) After the type of a value to mark the value as optional.
If a var or constant could be a nil, the Var must is declared as optional
Optional is an enumeration
Optional Example:
1. Pnumber is a string constant
2. When cast it to a int, it might is a int or nil since some strings can not casted, liked "good"
3. Optional Binding statement is if let A = b {}
If You is sure the optional does contain a value, it can be accessed by pnumber! (implicitly optional)
Sample Code:
Let Pnumber = "123"
Let Converternumber = Int (possiblenumber!)
If Let Actualnumber = Int (pnumber) {//casting and force it to a constant. A Constan
Print ("\ ' \ (pnumber) \ ' Have an integer valuel of \ (Actualnumber)")
} else {
Print ("\ ' \ (pnumber) \ ' could not is converted to an integer")
}
Swift Optionals-1