Complete the code to declare an optional integer variable.
var number: Int[1]In Swift, adding a ? after a type declares it as optional, meaning it can hold a value or be nil.
Complete the code to safely unwrap an optional using if-let.
if let safeNumber = optionalNumber[1] { print(safeNumber) }
The if let syntax uses = to assign the unwrapped value if it exists.
Fix the error in force unwrapping an optional.
let forcedValue = optionalValue[1]Force unwrapping uses ! to get the value inside an optional, but it can crash if nil.
Fill both blanks to create a dictionary comprehension filtering non-nil values.
let filtered = dictionary.compactMapValues { $0[1] } .filter { $0[2] nil }Use ? to safely unwrap in compactMapValues and != to filter out nil values.
Fill all three blanks to unwrap an optional with guard and provide a default value.
guard let value = optionalValue[1] else { return [2] } let finalValue = value[3]
Use ? for optional chaining, 0 as default return, and ! to force unwrap after guard.
