Complete the code to declare a mutable array.
var numbers = [1]let instead of var makes the array immutable.Using var with an array literal [1, 2, 3] creates a mutable array.
Complete the code to add an element to a mutable array.
var fruits = ["apple", "banana"] fruits.[1]("orange")
remove or pop which remove elements.insert without specifying an index.The append method adds a new element to the end of a mutable array.
Fix the error in the code to modify an immutable array.
[1] colors = ["red", "green", "blue"] colors.append("yellow")
let which makes the array immutable.const or final.You cannot modify an array declared with let. To fix the error, declare the array with var instead of let.
Fill both blanks to create a mutable dictionary and add a new key-value pair.
var capitals = [1] capitals["France"] = [2]
let instead of var for mutable collections.Use var with a dictionary literal to create a mutable dictionary. Then assign a new value to a key to add it.
Fill all three blanks to declare an immutable set and check if it contains a value.
let primes: Set<Int> = [1] let containsFive = primes.[2](5) print(containsFive) // [3]
var instead of let.containsValue.false when the value is actually in the set.Use a set literal with square brackets to declare the set. Use the contains method to check membership. The result is true because 5 is in the set.