TTS Swift Notes: The Basics Flashcards
What does Int stands for?
Integer
A Double accounts for what?
A floating-point value up to 15 spaces after the decimal.
A Float accounts for what?
Numbers with decimals at least 6 spaces after the decimal.
What does Bool stand for?
Boolean
What does a String represent?
Textual data.
What do tuples do?
They enable the creation and passing around of groupings of values. You can use a tuple to return multiple values from a function as a single compound value.
Optionals return what two values?
There is a value and it equals x OR there isn’t a value at all.
What types do optionals work for?
All, not just classes.
Can the value of a constant be changed once it’s been set?
No.
What keyword declares a constant?
let
What keyword declares a variable?
var
What the is proper way to name a variable/constant? currentLoginAttempt or current_login_attempt?
The first.
Can you declare multiple constants or variables on a single line?
Yes
How do you declare multiple constants or variables on a single line?
By separating them with commas.
What does type annotation do?
It is clear about the kind of values a constant or variable can store.
How do you write a type annotation?
By placing a colon after the constant or variable name, followed by a space, followed by the name of the type to use. EX: var welcomeMessage: String
How do you read the following?: var welcomeMessage: String
“Declare a variable called welcomeMessage that is of type String.”
Can you define multiple related variables of the same type on a single line?
Yes
How do you define multiple related variables of the same type on a single line?
Separate the variables by commas, follow the last variable with a colon, then declare the type annotation. EX: var red, green, blue: Double
If you do not declare a type, how does Swift know what type it is?
It infers it.
What five items can constant and variable names not contain?
- Whitespace characters
- Mathematical symbols
- Arrows
- Private-use (or invalid) Unicode code points
- line- and box-drawing characters
What can constant and variable names not start with?
A number.
Once you’ve declared a constant or variable of a certain type, can you redeclare it again with the same name or change it to store values of a different type?
No.
Can you change a constant into a variable or vice versa?
No.