Ch 2: Introduction to Swift Programming Flashcards

1
Q

String interpolation: How is it used to construct a new string value? Hint: 4 steps:
> What it uses
> Starts and ends with
> How to delineate internal parts
> Some parts do not have to be delineated

==> P. 26

A

> Use a mix of constants, variables, literals, and expressions by including their values inside a string literal.
The enclosing string literal starts and ends with a double quote mark.
Each item that you insert into the string literal is wrapped in a pair of parentheses, prefixed by a backslash ().
The string text inside the double quotes (part of the string literal itself) do not have to be wrapped in parenthesis and prefixed by a ().

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

What are the two ways that Swift knows an identifier’s type?

==> P. 25

A

1) By type inference

2) By type annotation

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

How does type inference work?

==> P. 25

A

An identifier (variable, constant, etc.) is given a value. The format of the value supplies type information to Swift.

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

How does type annotation work?

==> P.25

A

The type of an identifier is explicitly specified in the initializer statement.

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

What are the naming rules for identifiers for variables and constants?

==> P. 26 - 27

A

Identifiers can contain most valid Unicode characters with the following exceptions:

Typically begin with a lower case letter.
May not start with a number.
Cannot contain whitespace, math symbols, arrows, drawing characters, etc.

Camel case is frequently used.

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

What type of letter do type names begin with?

==> P. 26

A

Uppercase.

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

Give examples of a variable identifier being declared as follows:
With type inference
With type annotation
With type inference and annotation

==> P. 25

A
var number1 = 4
var number1: Int
var number1: Int =4
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q
Give examples of a constant identifier being declared as follows:
Type inference (via assignment)
With type annotation
With type annotation and assignment

==> P. 27

A
let number2 = 25
let number2: Int
let number2: Int = 25
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is an expression? Give two answers.
One answer is essentially a simplification of the other.

==> P. 28

A

1) Any portion of a statement that has calculations.
2) Any portion of a statement that has a value associated with it.
* **==> Explore further, find examples

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

What are the six comparison operators?
Hint: They exist in three pairs, with each pair having complementary operators.

==> P. 30

A

==, != equal to, not equal to
>, < greater than, less than
>=, <= greater than or equal to, less than or equal to

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

What is the format of the simple if statement?

==> P. 29 - 31

A

if condition {
body of statements
}

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

Are braces required in an if statement?

==> P. 31

A

Yes - braces are required in an if statement.

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

What are some “extended” comparison operators in addition to the six “normal” ones?

==> P. 30

A
===  identical to
!==   not identical to

“Identical to” means the two things being compared represent the same object, structure, or enumeration.

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

What represents an empty control statement (such as if)?

==> P. 32

A

A pair of braces: {}

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