Complete the code to add two numbers safely using Swift operators.
let sum = 5 [1] 3
The plus operator (+) adds two numbers safely in Swift.
Complete the code to check if two values are equal using a safe operator.
if a [1] b { print("Equal") }
The double equals operator (==) safely compares two values for equality in Swift.
Fix the error in the code by choosing the correct operator for safe division.
let result = 10 [1] 0
The forward slash (/) is the correct division operator in Swift. Division by zero will cause a runtime error, so operator safety means checking the divisor before dividing.
Fill both blanks to create a dictionary comprehension that filters keys safely.
let filtered = dictionary.filter { $0.key [1] "a" && $0.value [2] 10 }The code filters dictionary entries where the key equals "a" and the value is greater than 10, using safe comparison operators.
Fill all three blanks to safely create a dictionary with keys uppercased and values filtered.
let safeDict = dictionary.reduce(into: [:]) { result, pair in
if pair.value [1] 5 {
result[[2]] = [3]
}
}The code filters dictionary entries where the value is greater than 5, then adds them to a new dictionary with keys uppercased and original values, using safe operators.