Getting Started with App Development [Section 3: Constants, Variables, & Data Types] Flashcards
___________ are most frequently used to explain difficult sections of code, provide copyright information, at the top of a file, and to offer dating information
Comments
Swift also supports ___________ _____________, which group multiple values into a single constant or variable
collection types
One collection type is named an __________; it stores an ordered list of values
Array
Another collection type is named a __________, which contains keys that help you look up specific values
Dictionary
Here’s an example of creating a type definition
struct Person {
let firstName: String
let lastName: String
func sayHello() {
print(”Hello there! My name is (firstName) (lastName).”)
}
}
A ________ _________ declares the information it stores and its capabilities or actions
type definition
The information that a type definition stores
property
A type definition’s action/ capability
method
When creating a type and assigning it to a variable or constant, you’re making a version or ________ of the type
instance
Swift is a type-_______ language
safe
Type-safe languages encourage or require clarity about the types of values your ______ can work with
code
When compiling your code, Swift performs _________ __________ on all of your constraints and variables; it also flags any mismatched types as errors
type checking
In Swift, you’re unable to assign a ________ of one type to a variable of another type
variable
Swift allows you to put _________ in your numbers as a way of formatting for easier reading
underscores
e.g.,
var largeUglyNumber = 1000000000
var largePrettyNumber = 1_000_000_000
Swift uses _________ __________ to make assumptions about the type based on the value assigned to the constant or variable
type inference
e.g.,
let cityName = “San Francisco”
// “San Francisco” is obviously a String
, so the compiler
automatically assigns the type of cityName to a String
.
let pi = 3.1415927
// 3.1415927 is a number with decimal points, so the compiler
automatically assigns the type pi
to a Double
.