Fundamentals Flashcards
Keyword to create an enumeration Type?
enum
What type of syntax do you use to access enums?
dot syntax
Can you use an enum in a switch statement?
Yes
How do you declare an enum with raw values?
enum ENUM_NAME: String {
case ENUM_CASE1 = “VALUE1”
case ENUM_CASE2 = “VALUE2”
}
How do you declare an enum with associated values?
enum ENUM_NAME { case ENUM_CASE1(CASETYPE1) case ENUM_CASE2(CASETYPE2) }
How do you access the value associated with an enum case in a switch statement?
case .ENUM_CASE(let VALUENAME):
What do you call variables within a Struct, Class?
Properties of a Struct, Class
Keyword to create different enumeration choices?
case
Do you have to write initializers for Structs?
No. Swift will automatically create a “memberwise initializer”
Do all properties of a struct need to be declared when instantiating an instance of a structure?
Yes
What do you call the object created from a Struct/Class?
Instance of a Struct/Class
Are dictionaries ordered or unordered?
Unordered
How do you access the enum’s raw value?
.rawValue getter
When you declare a variable as an enum type and you are setting it, can you use a shorter syntax?
Yes, use dot syntax. (exp: .caseItem)
How do you declare and initialize a dictionary using a literal format?
var DICT = [
“KEY1”: “VALUE1”,
“KEY2”: “VALUE2”
]
What do you call functions within a Struct, Class?
Methods of a Struct, Class
Are “switch case” statements labels capitalized?
No
How do you force unwrap optionals?
Using the bang (!) symbol after a variable name
When you set the value of a dictionary key to nil, does it remove it from the collection?
Yes
How do you declare and initialize an empty dictionary of type String: Int
var DICT: [String: Int] = [:]
What method can you call that returns a tuple containing an index and the value?
array.enumerated()
When Iterating a dictionary, could you get a different order of items?
Yes
When getting the value of a dictionary does it return an optional value?
Yes
What keyword do you use to define a tuple?
Parenthesis (ITEM1, ITEM2)