You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
Q21. How many values does vals have after this code is executed?
var vals = Set<String> = ["4", "5", "6"]
vals.insert("5")
three
four
eight
This code contains an error.
Q22. 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.
Q23. How can you avoid a strong reference cycle in a closure?
an instance of any class
all of these answers
an instance of an optional type
an instance of function type
Q24. What is wrong with this code?
if let s = String.init("some string") {
print(s)
}
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.
Q25. Which code snippet correctly creates a typealias closure?
typealias CustomClosure: () -> ()
typealias CustomClosure { () -> () }
typealias CustomClosure -> () -> ()
typealias CustomClosure -> () {}
Q26. How do you reference class members from within a class?
self
instance
class
this
Q27. All value types in Swift are **_** under the hood?
structs
classes
optionals
generics
Q28. What is the correct was to ass a value to this array?
var strings = [1, 2, 3]
all of these answers
strings.append(4)
strings.insert(5, at: 1)
strings += [5]
Q29. How many times will this loop be executed?
for i in 0...100 {
print(i)
}
0
101
99
100
Q30. What can AnyObject represent?
an instance of any class
an instance of an optional type
an instance of a function type
all of these answers
Q31. What does this code print?
typealias Thing = [String:Any]
var stuff : Thing
print(type(of:stuff))
Dictionary
ERROR
Thing
Dictionary<String, Any>
Q32. What is the value of test in this code?
var test = 1 == 1
TRUE
1
This code contains an error.
YES
Q33. What is the value of y?
var x : Int?
let y = x ?? 5
0
nil
This code contains an error.
5
Q34. What is the value of y?
let x = ["1","2"].dropFirst()
let y = x[0]
1
nil
This code contains an error.
2
Q35. What is the value of t after this code is executed?
let names = ["Larry","Sven","Bear"]
let t = names.enumerated().first().offset
This code is invalid.
0
1
Larry
Q36. What is the value of test after this code executes?
let vt = (name: "ABC", val: 5)
let test = vt.0
ABC
0
5
name
Q37. What is the base class in this code?
class LSN : MMM {
}
MMM
LSN
There is no base class.
This code is invalid.
Q38. What does this code print to the console?
var userLocation: String = "Home" {
willSet(newValue) {
print("About to set userLocation to \(newValue)...")
}
didSet {
if userLocation != oldValue {
print("userLocation updated with new value!")
} else {
print("userLocation already set to that value...")
}
}
}
userLocation = "Work"
About to set userLocation to Work… userLocation updated to 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
Q39. 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
Q40. 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
Q41. What is the inferred type of x?
let x = ["a", "b", "c"]
String[]
Array<String>
Set<String>
Array<Character>
Q42. What is the value of oThings after this code is executed?
let nThings: [Any] = [1, "2", "three"]
let oThings = nThings.reduce("") { "\($0)\($1)" }
11212three
115
12three
Nothing, this code is invalid.
Q43. How would you call a function that throws errors and also returns a value?