Tag: Optional bindings

  • Choosing between guard statement and if let

    Swift offers two important features for handling optionals: the guard statement and if let, also known as optional binding. What is guard? The guard statement is ideal for scenarios where you want to ensure certain conditions are met before proceeding with the execution of your code. If these conditions are not met, the guard statement…

  • Optional binding and Optional Chaining

    Swift has a feature that lets users to assign optional value to a variable or a constant. Optional variable or constant can contain a value or a nil value. Let us take the following example which tries to find a given string in a array of string. Optional Binding var fruits = [“Apple”,”Orange”,”Grape”,”Mango”] let searchIndex…