Question: Question 1 Enumerations in Swift can define computed properties. True False Question 2 Raw values are the same as associated values. True False Question 3

Question 1

Enumerations in Swift can define computed properties.

True

False

Question 2

Raw values are the same as associated values.

True

False

Question 3

Which of the following allows you to store additional custom information along with a case in a Swift enumeration?

associated value

computed property

method

static value

Question 4

Given the following lines of code and a valid Trip class that has a property called title:

var trip: Trip? trip?.title = "Vacation to San Francisco"

What will happen when the above lines execute?

A trip instance is created and the title is set on the instance.

Attempting to access title on trip crashes the program, because trip was not initialized with a Trip object and is nil.

Because optional chaining is used and trip is nil, there will be no attempt to access title on trip.

The nil-coalescing operator ensures that a valid trip instance is created before title is set on it.

Question 5

Color is an enumeration that contains the cases red, green, and blue.

Given: var color = Color.red

Is the following allowed on a line after the above line of code?

color = .green

Yes

No

Question 6

Enumerations in Swift cannot have instance methods.

True

False

Question 7

Given the following:

let defaultAudioLevel = 0.5 var userSetAudioLevel: Double? var audioLevel = userSetAudioLevel ?? defaultAudioLevel

Which of the following is used in the Swift code?

Nil-Coalescing Operator

Optional Chaining

Range Operator

Subscripts

Question 8

Because not every raw value will return an enumeration case, the raw value initializer for an enumeration has to be a failable initializer.

Given the following:

var color = RainbowColor(rawValue: 6)

What type is color?

Color

Color?

Color!

Int

Int?

Int!

RainbowColor

RainbowColor?

RainbowColor!

Question 9

Optional chaining and the nil-coalescing operator cannot be used together in the same line of code.

True

False

Question 10

Given the following OuterPlanets enumeration:

enum OuterPlanets: Int { case mars = 4, jupiter, saturn, uranus, neptune }

What is the rawValue for saturn?

2

3

4

5

6

7

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!