Swift Again Flashcards

1
Q

Variables and Constants

A

Constants and variables associate a name with a value of a particular type.

Constant: let
Variable: var

Constants cannot be changed
Variables can be changed

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

How do you declare multiple constants or variables

A

Separate them by comma

var x = 6, y = 10

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

Type annotation

A

Used as a way to be clear about what type of values a variable or constant can store.

To do this, place a colon after constant or variable name.

For example:

var thisExample: String

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

How do you store multiple type annotations in one line?

A

Separate them by commas.

For example:

var red, green, blue: double

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

What can’t a variable name be?

A
Whitespace characters
Mathematical symbols
Arrows
Private-use (or invalid)
Unicode code-points
Box drawing characters

They also can’t start with a number.

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

String Interpolation

A

Combining two or more variables while adding a new string

Use backslash to input existing variables without severing the string
For example: 
let bananas = 5
let apples = 16
let oranges = 7
print("I am shopping for \(bananas) bananas, \(apples) apples, and \(oranges) oranges. In total, I will buy \(bananas + apples + oranges) pieces of fruit.")

The result:

I am shopping for 5 bananas, 16 apples, and 7 oranges. In total, I will buy 28 pieces of fruit.

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

What are comments?

A

Pieces of information I can add to tell me what my code does.

Use // to create a comment

Use /* create a comment
over multiple lines /*

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

What are nested comments?

A
/* Comments that started as multiline 
/* and become nested */
And then you can add a new comment to end the first multiline comment */
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Use of semicolons in Swift

A

Not required in the same way it is in other languages, but it is necessary in order to in order to write multiple separate statements like:

let catDog = “fun”; print(catDog)

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

Integers

A

Whole numbers

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

Signed Integers

A

Unknown definition, but Swift provides

6, 16, 32, and 64 bit forms

8-but unsigned integer is a UInt-8

32 signed integer is Int32

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

Integer Bounds

A

The minimum and maximum values of each integer type with its min and max properties.

Example:

let minValue = UInt8.min // minValue is equal to 0, and is of type UInt8
let maxValue = UInt8.max // maxValue is equal to 255, and is of type UInt8

The values of these properties are of the appropriate-sized number type (such as UInt8 in the example above) and can therefore be used in expressions alongside other values of the same type.

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

Int

A

In most cases, it’s not necessary to pick a certain size for your integer. Int is an additional integer type that has the same size as the platforms current native word size.

For example:

On a 32-bit platform, Int is the same size as Int32.
On a 64-bit platform, Int is the same size as Int64.

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