Swift Flashcards

1
Q

Escape variable from a string

A

“Model is (model)”

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

variable vs const

A

var and let

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

what are the data types

A

Int, Double, Float, String, Bool

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

Define a tuple, and access the second value

A

let myTuple = (1, 15, “Test”)
var val = myTuple.1

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

Deconstruct a tuple.

A

let (x, _, z) = myTuple

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

Define a tuple with variable names, and access the second value

A

let myTuple = (first: 1, second: 2, str: “test”
var val = myTuple.second

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

What happens when using a variable that has a non-optional type, but hasn’tbeen assigned a value?

A

An error stating that the value is being used before being initialized.

It is not nil.

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

Define an optional Int and use it

A

let x: Int?
if (x != nil) {
print(x!)
}

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

Unwrap multiple optionals

A

if let x = opt1, let y = opt2, let z = opt3 {
}

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

Difference between Int? and Int! when declaring variables

A

? requires forced unwrapping. AKA using myVal! when accessing or using let x = myVal in if condition.
! means it is implicitly unwrapped and can be used without checking if nil

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

Can var myString: String = nil be used?

A

No, only optionals can be nil

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

Upcast UIButton to UIControl

A

let myControl = myButton as UIControl

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

Downcast UIScrollView to UITextView

A

if let myTextView = myScrollView as ? UITextView {
}

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

CHeck if something is a Class

A

if myObj is Class {
}

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