Complete the code to declare a constant in Swift.
let [1] = 10
In Swift, let declares a constant, which cannot be changed after assignment. This helps with safety by preventing accidental changes.
Complete the code to safely unwrap an optional in Swift.
if let value = [1] { print(value) }
Using if let with an optional variable (like optionalValue) safely unwraps it if it contains a value, preventing runtime errors.
Fix the error in the code by choosing the correct type for the variable.
var name: [1] = "Swift"
The variable name holds text, so its type must be String for the code to work correctly.
Fill both blanks to create a function that returns the sum of two integers.
func add(a: Int, b: Int) -> [1] { return a [2] b }
The function returns an Int and adds two integers using the + operator.
Fill all three blanks to create a dictionary comprehension that filters keys with values greater than 5.
let filtered = dictionary.filter { [1], [2] in [3] > 5 }The filter method uses a closure with key and value parameters, and filters where value is greater than 5.