Ch 2: Introduction to Swift Programming Flashcards
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
> 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 ().
What are the two ways that Swift knows an identifier’s type?
==> P. 25
1) By type inference
2) By type annotation
How does type inference work?
==> P. 25
An identifier (variable, constant, etc.) is given a value. The format of the value supplies type information to Swift.
How does type annotation work?
==> P.25
The type of an identifier is explicitly specified in the initializer statement.
What are the naming rules for identifiers for variables and constants?
==> P. 26 - 27
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.
What type of letter do type names begin with?
==> P. 26
Uppercase.
Give examples of a variable identifier being declared as follows:
With type inference
With type annotation
With type inference and annotation
==> P. 25
var number1 = 4 var number1: Int var number1: Int =4
Give examples of a constant identifier being declared as follows: Type inference (via assignment) With type annotation With type annotation and assignment
==> P. 27
let number2 = 25 let number2: Int let number2: Int = 25
What is an expression? Give two answers.
One answer is essentially a simplification of the other.
==> P. 28
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
What are the six comparison operators?
Hint: They exist in three pairs, with each pair having complementary operators.
==> P. 30
==, != equal to, not equal to
>, < greater than, less than
>=, <= greater than or equal to, less than or equal to
What is the format of the simple if statement?
==> P. 29 - 31
if condition {
body of statements
}
Are braces required in an if statement?
==> P. 31
Yes - braces are required in an if statement.
What are some “extended” comparison operators in addition to the six “normal” ones?
==> P. 30
=== identical to !== not identical to
“Identical to” means the two things being compared represent the same object, structure, or enumeration.
What represents an empty control statement (such as if)?
==> P. 32
A pair of braces: {}