Questions and Answers
- What is this code an example of?
- a syntax issue
- typecasting
- assignment
- initialization
- What is the error in this code?
- The guard is missing the else.
- Nothing is wrong.
- The guard is missing a then.
- The comparison is wrong.
- What is the raw/underlying type of this enum?
- There is none.
- String
- Any
- Int
- Why is dispatchGroup used in certain situations?
- It allows multiple synchronous or asynchronous operations to run on different queues.
- It allows track and control execution of multiple operations together.
- It allows operations to wait for each other as desired.
- all of these answers.
- What is this code an example of?
- string interpolation
- string compilation
- method chaining
- string concatenation
- What are the contents of `vals` after this code is executed?
- [10, 2]
- [2, 10]
- nil
- This code contains an error
- What does this code print?
- Dictionary
- Dictionary
- ERROR
- Thing
- Dictionary
- What is the value of y?
- This code contains an error
- 1
- 2
- nil
- What is the value of test in this code?
- TRUE
- YES
- 1
- This code contains an error
- What is the value of y?
- 5
- 0
- nil
- This code contains an error
- What is the type of this function?
- Int
- (Int, Int) -> Int
- Int
- Functions don't have types.
- What is the correct way to call this function?
- myFunc(5, b: 6)
- myFunc(5, 6)
- myFunc(a: 5, b: 6)
- myFunc(a, b)
- The Codable protocol is **\_**?
- a combination of Encodable and Decodable
- not a true protocol <<<<---Possibly correct as it's a typealias of Encodable and Decodable
- required of all classes
- automatically included in all classes
- What is the type of value1 in this code?
- String
- Int
- null
- test.count
- When a function takes a closure as a parameter, when do you want to mark is as escaping?
- when it's executed after the function returns
- when it's scope is undefined
- when it's lazy loaded
- all of these answers
- What's wrong with this code?
- Person has no initializers.
- Person has no base class.
- var name is not formatted corrrectly.
- address is a keyword.
- What is the value of names after this code is executed?
- ["BEAR", "JOE", "CLARK"]
- ["B", "J", "C"]
- ["Bear", "Joe", "Clark"]
- This code contains an error.
- What describes this line of code?
- a constant named val of type Int
- a variable named val of type item
- a constant named val of type Number
- a variable named val of type Int
- What is the error in this code?
- Extensions can't add properties. // although extensions technically can't contain stored properties
- Nothing is wrong with it.
- didSet takes a parameter.
- c is not a character.
- didSet and willSet are examples of **\_**?
- property observers
- key properties
- all of these answers
- newOld value calls
- What is wrong with this code?
- Use of self inside the closure causes retain cycle.
- You cannot assign a value to closure in this manner.
- You need to define the type of closure explicitly.
- There is nothing wrong with this code.
- How many values does vals have after this code is executed?
- three
- four
- eight
- This code contains an error.
- How can you avoid a strong reference cycle in a closure?
- Use a capture list to set class instances of weak or unowned.
- You can't, there will always be a danger of strong reference cycles inside a closure.
- Initialize the closure as read-only.
- Declare the closure variable as lazy.
- What is wrong with this code?
- This String initializer does not return an optional.
- String does not have an initializer that can take a String.
- = is not a comparison.
- Nothing is wrong with this code.
- Which code snippet correctly creates a typealias closure?
- typealias CustomClosure: () -> ()
- typealias CustomClosure { () -> () }
- typealias CustomClosure -> () -> ()
- typealias CustomClosure -> () {}
- How do you reference class members from within a class?
- self
- instance
- class
- this
- All value types in Swift are **\_** under the hood?
- structs
- classes
- optionals
- generics
- What is the correct way to add a value to this array?
- all of these answers
- strings.append(4)
- strings.insert(5, at: 1)
- strings += [5]
- How many times will this loop be executed?
- 0
- 101
- 99
- 100
- What can AnyObject represent?
- an instance of any class
- an instance of function type
- all of these answers
- an instance of an optional type
- What is the value of t after this code is executed?
- This code is invalid.
- This code does not compile.
- 0
- 1
- What is the value of test after this code executes?
- ABC
- 0
- 5
- name
- What is the base class in this code?
- MMM
- LSN
- There is no base class.
- This code is invalid.
- What does this code print to the console?
- About to set userLocation to Work? userLocation updated with new value!
- About to set userLocation to Work? userLocation already set to that value?
- About to set userLocation to Home? userLocation updated to new value!
- ERROR
- What must a convenience initializer call?
- a base class convenience initializer
- either a designated or another convenience initializer
- a designated initializer
- none of these answers
- Which object allows you access to specify that a block of code runs in a background thread?
- DispatchQueue.visible
- DispatchQueue.global
- errorExample need to be labeled as `throws`.
- DispatchQueue.background
- What is the inferred type of x?
- `String[]`
- `Array
` - `Set
` - `Array
`
- What is the value of `oThings` after this code is executed?
- 11212three
- 115
- 12three
- Nothing, this code is invalid.
- How would you call a function that throws errors and also returns a value?
- `!try`
- `try?`
- `try!`
- `?try`
- What is wrong with this code?
- Protocol functions cannot have return types.
- Protocol functions cannot have implementations.
- Nothing is wrong with it.
- `add` is a reserved keyword.
- In this code, what are `wheels` and `doors` examples of?
- class members
- This code is invalid.
- class fields
- class properties
- How do you designated a failable initializer?
- You cannot
- deinit
- `init?`
- init
- What is printed when this code is executed?
- five
- 5a
- `.asString()`
- 5
- In the function below, what are `this` and `toThat` examples of?
- none of these answers
- local terms
- argument labels
- parameters names
- What is wrong with this code?
- The interaction source is invalid
- The interaction variable is invalid
- There is nothing wrong with this code
- The comma in the print is misplaced
- Which of these choices is associated with unit testing?
- XCTest
- all of these answers
- @testable
- XCAssert
- In the code below, what is width an example of?
- This code contains error
- a closure
- a computed property
- lazy loading
- What data type is this an example of?
- a dictionary
- a tuple
- an optional
- This code contains error
- What is wrong with this code?
- You cannot assign a Double to a variable of type Int
- x is undefined
- x is a constant
- x has no type
- What will this code print to the console?
- Any
- test
- 1,2,3
- nil
- What is wrong with this code?
- There is nothing wrong with this code
- val is a constant and cannot be changed
- 5.0 and 10 are different types
- There is no semicolon
- How many parameters does the initializer for Test have?
- zero
- This code contains an error
- two
- Structs do not have initializers
- What prints to the console when executing this code?
- nil
- Nothing - this code contains an error
- Optional("test")
- test
- How can you sort this array?
- `vals.sort { $0 < $1 }`
- `vals.sort { (s1, s2) in s1 < s2 }`
- `vals.sort(by: <)`
- all of these answers
- DispatchQueue.main.async takes a block that will be
- not executed
- executed in the main queue
- none of these answers
- executed on the background thread
- When is deinit called?
- When a class instance needs memory
- All of these answers
- When the executable code is finished
- When a class instance is being removed from memory
- How do you declare an optional String?
- String?
- Optional[String]
- [String]?
- ?String
- How many times this code will be executed? ?OR? How many times will this loop be performed?
- one
- two
- three
- This code does not compile
- What does this code print?
- 1Bear
- BearBear
- TonyBear
- Nothing, this code is invalid
- What is true of this code?
- name can hold only a string value.
- name can hold either a string or nil value.
- Optional values cannot be `let` constants.
- Only non-empty string variables can be stored in name.
- What is the value of `val` after this code is executed?
- This code is invalid.
- 6
- 30
- 0
- What does this code print?
- 3
- 0
- other
- nil
- What is printed to the console when this code is executed?
- nil
- Nothing, since the code contains an error
- t
- zero
- What prints when this code is executed?
- []
- ["3", "2", "1"]
- [321]
- ["1", "2", "3"]
- What enumeration feature allows them to store case-specific data?
- associated values
- integral values
- raw values
- custom values
- In the code below, AOM must be a(n)?
- class
- protocol
- enumeration
- struct
- What is the value of numbers in the code below?
- [1,3,5]
- []
- [2,4,6]
- nil
- What is the type of `vals` in this code?
- Array(char)
- [Any]
- Array
- [Generic]
- How can you extract val to `x` in tuple `vt`
- let x = vt.1
- all of these answers
- let x = vt.val
- let (`_`, x) = vt