Question: Could someone please help me answer some Swift programming questions? Thanks, I will thumbs up! 1. Given the following in Swift: class User { let
Could someone please help me answer some Swift programming questions? Thanks, I will thumbs up!
1. Given the following in Swift:
class User { let firstName: String let lastName: String let userID: String
init(firstName: String, lastName: String, userID: String) { self.firstName = firstName self.lastName = lastName self.userID = userID } }
Which of the following is the correct way to create an instance of User?
A. var user = User("Sally", "Garcia", "sgarcia")
B. var user = User(firstName: "Sally", lastName: "Garcia", userID: "sgarcia")
C. var user = new User("Sally", "Garcia", "sgarcia")
D. var user = new User(firstName: "Sally", lastName: "Garcia", userID: "sgarcia")
.
2. You must decide what determines if two instances are equal when you create your own classes and structures.
A. True
B. False
.
3. Given the following in Swift:
struct Kilometers { var kilometers: Double init(fromMiles miles: Double) { kilometers = miles * 1.60934 } init(fromMeters meters: Double) { kilometers = meters / 1000.0 } }
Which of the following is the correct way to create an instance of the struct if the known distance is in miles?
A. let distance = Kilometers(fromMiles: 2.5)
B. let distance = Kilometers(miles: 2.5)
C. let distance = new Kilometers(fromMiles: 2.5)
D. let distance = new Kilometers(miles: 2.5)
E. let distance =Kilometers(2.5 as miles)
. 4. Objects are comprised of data variables and functions. The data variables and functions are referred to as class members. Which of the following is the name used for data variables in an object?
A. methods
B. optionals
C. properties
D. characteristics
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
