Swift Types - Part Two Flashcards

1
Q

Types - definition.

A

A construct to represent different kinds of data.

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

“I am a String, Because”

A

“I am wrapped in quotes”

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

How to Add Strings: (2 Ways).

A

Concatenation

or…

String Interpolation

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

String Interpolation

A

String Interpolation is a way to construct a new string value from a mix of other strings. Same constants as before:

let country = "United States of America" let state = "North Carolina"let city = "Charlotte"let street = "West Street" Example: let interpolatedAddress = "\(country), \(state), \(city)"

Using String Interpolation, you can evaluate the contents of more than just strings.

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

Concatenation

A

// Concatenationlet country = "United States of America"let state = "North Carolina"let city = "Charlotte"let street = "West Street"let concatenatedAddress = country + ", " + state + ", " + city

the first method is called concatenation. This is an overly complicated sounding word, but it’s just programmer speak for adding two strings together.

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

Kinds of Types

A
  • Strings
  • Numbers & Booleans
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

An Integer (Int) is a:

A

Whole #, like 42 or -25

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

Floating Point Numbers (Double Or Float)
Default is double

A

Numbers With a Fractional Component

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

Boolean Type (Bool)

A

True (1) or False (0)

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

Type Inference

A

Type inference enables the compiler to deduce the type of a particular expression automatically by examining the values we provide.

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

Type Safety

A

Cannot use an int instead of a string once declared

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

To Explicity State the Type of Data (examples):

A

// Integerlet secondValue: Int = 4// Stringlet bestPlayer: String = "Micheal Jordan"// Doublelet averagePointsPerGame: Double = 30.1// Booleanlet hallOfFame: Bool = true

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