Please help with these Swift Questions I will thumbs up on rating!!!!! 1. Which
ID: 3910705 • Letter: P
Question
Please help with these Swift Questions
I will thumbs up on rating!!!!!
1. Which of the following is the declaration of an optional that is not implicitly unwrapped?
A. var count = 20
B. var count: Int
C. var count: Int?
D. var count: Int!
2. Swift does not allow the declaration of multiple constants or variables on a single line separated by commas like the following:
var latitude = 38.9473, longitude = -92.3287, altitude = 758.2
A. true
B. false
3. Swift allows the definition of multiple variables on a single line, separated by commas, with a single type specified after the last variable name like the following:
var i, j, k: Double
A. true
B. false
4.Give the following code:
var name = "Sally"
let age = 19
Which of the following shows string interpolation in use?
A. let output = "(name) is (age) years old."
B. let output = name + " is " + String(age) + " years old"
C. let output = name + " said, "Hello!""
D. let ageString = String(age)
5. Given the following function, what is the proper way to call the function?
func add(_ value1: Int, to value2: Int) -> Int {
return value1 + value2
}
A. let result = add(value1: 5, value2: 6)
B. let result = add(5, value2: 6)
C. let result = add(5, to: 6)
D. let result = add(value1: 5, to value2: 6)
Explanation / Answer
1.
Declaration of an optional that is not implicitly unwrapped
var count: Int!
TO declare the implicitly unwrapped we must use !
Option d
2.
Swift does not allow the declaration of multiple constants or variables on a single line separated by commas like the following:
var latitude = 38.9473, longitude = -92.3287, altitude = 758.2
False
var latitude = 38.9473, longitude = -92.3287, altitude = 758.2 is a valid declaration
swift allow the declaration of multiple constants or variables on a single line separated by commas.
3.
Swift allows the definition of multiple variables on a single line, separated by commas, with a single type specified after the last variable name like the following:
var i, j, k: Double
It is possible to define multiple related variables of the same type on a single line.
True
4.
.Give the following code:
var name = "Sally"
let age = 19
String interpolation in use let output = "(name) is (age) years old."
Option a
5.
func add(_ value1: Int, to value2: Int) -> Int { // called function
return value1 + value2
}
let result = add(value1: 5, to value2: 6) // calling function also include the type
Option d