Please help with these swift problems I will thumbs up in rating !!!!!! 1. Given
ID: 3910708 • Letter: P
Question
Please help with these swift problems
I will thumbs up in rating !!!!!!
1. Given the following function, what is the proper way to call the function?
func add(_ x: Int, _ y: Int) -> Int {
return x + y
}
A. let result = add(x: 5, y: 6)
B. let result = add(_ x: 5, _ y: 6)
C. let result = add(Int: 5, Int: 6)
D. let result = add(5, 6)
E. let result = add(5: Int, 6: Int)
2. Given the following tuple:
let error = (errorCode: 101, message: "Invalid value.")
Is the following allowed?
let (code, message) = error
A. Yes
B. No
3. Given the following tuple:
let error = (101, "Invalid value.")
Which of the following accesses the second element of the tuple that is a String?
A. error.0
B. error.1
C. error[0]
D. error[1]
E. error.String
4. Given the following tuple:
let error = (errorCode: 201, message: "Invalid value.")
Which of the following can be used to access the second element ("Invalid value.") of the tuple?
A. error[1]
B. error["message"]
C. error{"message"}
D. error.message
E. errorMessage
5. Given:
var name: String? = "Dale"
Which of the following is a safe way to test if name has a value and unwrap the value and make it available as a temporary constant if it does?
A. name!
B. if let name = name { // code }
C. if name? { // code }
D. if name { // code }
Explanation / Answer
Please feel free to ask for any explanation needed regarding the answers.
Answers:
1. B
2. A
3. B
4. D
5. A