The Basics Flashcards

1
Q

How do you declare variables and constants?

How do you declare multiple constants/variables at the same time

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

How do you provide a type annotation?

A

var welcomeMessage: String

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

How do you use type annotation to define multiple related variables?

A

var red, green, blue: Double

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

How does print() work?

A

let friendlyWelcome = “Bonjour”

print(friendlyWelcome) // printss “Bonjour”

To use that value in a string:

print(“The current value of friendlyWelcome is (friendlyWelcome)”)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How do you perform an integer conversion with the following in order to add them together:

let twoThousand: UInt16 = 2_000

let one: UInt8 = 1

A

Create a new constant of the type we want the number to use.

let twoThousandAndOne = twoThousand + UInt16(one)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

How would you convert Integer to Floating-Point for the following so we can add them together?

let three = 3;

let pointOneFourOneFiveNine = 0.14159

A

let pi = Double(three) + pointOneFourOneFiveNine

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

How do you convert a floating-point to integer and how does it work with the decimal points? Use Pi as an example.

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

How do you safely work with an optional in Swift?

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

How does Optional Binding work?

A

It assigns an optional values to a variable after checknig to make sure there is a value there.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

How do you include multiple optional bindings and boolean conditions in a single if statement?

A

They need to be seperated by commas, if any of the values in the optional bindings are nil or any Boolean condition evaluaties to false, the whole if statement’s coniditon is considered to be false. Example below:

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

In general, why would you want to implicitly unwrap an optional?

A

Sometimes it’s clear from a programs’ structure tat an optiona will always have a value, after that value is first set. In these cases it’s useful to remove the need to check and unwrap the optional’s value every time it’s accessed, because it can be safely assumed to have a value all the time.

You can think of an implicitly unwrapped optional as giving permission for the optional to be unwrapped automatically whenever it’s used.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is the difference between Assertions and Preconditions?

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

How would you write an assertion regarding ensuing age is >= 0?

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is an alternate way to use assertions with conditionals?

A

using the assertionFailture( ) function. It forces an assertion fail with the text you enter:

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

How do you write a precondition?

A

put in a condition that must be true

precondition(index > 0, “Index must be greater than zero,”)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly