Complete the code to declare a simple Swift function.
func greet() -> String {
return [1]
}The function must return a string literal enclosed in quotes.
Complete the code to declare a variable with type Int.
var number: [1] = 10
The variable 'number' is declared as an integer type, so use Int.
Fix the error in the function declaration to compile correctly.
func add(a: Int, b: Int) -> [1] { return a + b }
The function adds two integers and returns an integer, so the return type must be Int.
Fill both blanks to create a dictionary comprehension that maps numbers to their squares for numbers greater than 3.
let squares = Dictionary(uniqueKeysWithValues: (4...7).map { [1] in let [2] = [1] * [1]; ([1], [2]) })
We use 'num' and 'val' as variable names in the closure to map numbers to their squares.
Fill all three blanks to create a dictionary comprehension that maps uppercase letters to their ASCII values for letters 'a' to 'd'.
let asciiDict = Dictionary(uniqueKeysWithValues: ("a"..."d").map { [1] in let [2] = [1].uppercased(); ([1].uppercased(), Int([3].unicodeScalars.first!.value)) })
The closure uses 'letter' and 'char' as parameters; the uppercase letter is the key, and its ASCII value is the value.