let val = (Double)6
- a syntax issue
- typecasting
- assignment
- initialization
let x = 5
guard x == 5 { return }
- The guard is missing the else.
- Nothing is wrong.
- The guard is missing a then.
- The comparison is wrong.
enum Direction {
case north, south, east, west
}
- There is none.
- String
- Any
- Int
- 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.
let val = 5
print("value is: \(val)")
- string interpolation
- string compilation
- method chaining
- string concatenation
var vals = [10, 2]
vals.sort { (s1, s2) -> Bool in
s1 > s2
}
- [10, 2]
- [2, 10]
- nil
- This code contains an error
typealias Thing = [String:Any]
var stuff: Thing
print(type(of: stuff))
- Dictionary<String, Any>
- Dictionary
- ERROR
- Thing
let x = ["1", "2"].dropFirst()
let y = x[0]
- This code contains an error
- 1
- 2
- nil
var test = 1 == 1
- TRUE
- YES
- 1
- This code contains an error
var x: Int?
let y = x ?? 5
- 5
- 0
- nil
- This code contains an error
func add(a: Int, b: Int) -> Int { return a+b }
- Int
- (Int, Int) -> Int
- Int
- Functions don't have types.
func myFunc(_ a: Int, b: Int) -> Int {
return a + b
}
- myFunc(5, b: 6)
- myFunc(5, 6)
- myFunc(a: 5, b: 6)
- myFunc(a, b)
- 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
let value1 = "\("test".count)"
- String
- Int
- null
- test.count
- when it's executed after the function returns
- when it's scope is undefined
- when is's lazy loaded
- all of these answers
class Person {
var name: String
var address: String
}
- Person has no initializers.
- Person has no base class.
- var name is not formatted corrrectly.
- address is a keyword.
let names = ["Bear", "Joe", "Clark"]
names.map { (s) -> String in
return s.uppercased()
}
- ["BEAR", "JOE", "CLARK"]
- ["B", "J", "C"]
- ["Bear", "Joe", "Clark"]
- This code contains an error.
let val = 5
- 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
extension String {
var firstLetter: Character = "c" {
didSet {
print("new value")
}
}
}
- 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.
- property observers
- key properties
- all of these answers
- newOld value calls
self.callback = {
self.attempts += 1
self.downloadFailed()
}
- 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.
var vals = Set<String> = ["4", "5", "6"]
vals.insert("5")
- three
- four
- eight
- This code contains an error.
- 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.
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.
- typealias CustomClosure: () -> ()
- typealias CustomClosure { () -> () }
- typealias CustomClosure -> () -> ()
- typealias CustomClosure -> () {}
- self
- instance
- class
- this
- structs
- classes
- optionals
- generics
var strings = [1, 2, 3]
- all of these answers
- strings.append(4)
- strings.insert(5, at: 1)
- strings += [5]
for i in 0...100 {
print(i)
}
- 0
- 101
- 99
- 100
- an instance of any class
- an instance of function type
- all of these answers
- an instance of an optional type
typealias Thing = [String:Any]
var stuff : Thing
print(type(of:stuff))
- Dictionary
- ERROR
- Thing
- Dictionary<String, Any>
let names = ["Larry", "Sven", "Bear"]
let t = names.enumerated().first().offset
- This code is invalid.
- This code does not compile.
- 0
- 1
- Larry
let vt = (name: "ABC", val: 5)
let test = vt.0
- ABC
- 0
- 5
- name
class LSN : MMM {
}
- MMM
- LSN
- There is no base class.
- This code is invalid.
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 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
- a base class convenience initializer
- either a designated or another convenience initializer
- a designated initializer
- none of these answers
- DispatchQueue.visible
- DispatchQueue.global
- errorExample need to be labeled as
throws
. - DispatchQueue.background
let x = ["a", "b", "c"]
-
String[]
-
Array<String>
-
Set<String>
-
Array<Character>
let nThings: [Any] = [1, "2", "three"]
let oThings = nThings.reduce("") { "\($0)\($1)" }
- 11212three
- 115
- 12three
- Nothing, this code is invalid.
-
!try
-
try?
-
try!
-
?try
protocol TUI {
func add(x1 : Int, x2 : Int) -> Int {
return x1 + x2
}
}
- Protocol functions cannot have return types.
- Protocol functions cannot have implementations.
- Nothing is wrong with it.
-
add
is a reserved keyword.
class Car {
var wheels: Int = 4
let doors = 4
}
- class members
- This code is invalid.
- class fields
- class properties
- You cannot
- deinit
-
init?
- init
let dbl = Double.init("5a")
print(dbl ?? ".asString()")
- five
- 5a
-
.asString()
- 5
func add(this x: Int, toThat y: Int)->{}
- none of these answers
- local terms
- argument labels
- parameters names
for (key, value) in [1: "one", 2: "two"]{
print(key, value)
}
- The interaction source is invalid
- The interaction variable is invalid
- There is nothing wrong with this code
- The comma in the print is misplaced
- XCTest
- all of these answers
- @testable
- XCAssert
class Square{
var height: Int = 0
var width : Int {
return height
}
}
- This code contains error
- a closure
- a computed property
- lazy loading
let vals = ("val", 1)
- a dictionary
- a tuple
- an optional
- This code contains error
var x = 5
x = 10.0
- You cannot assign a Double to a variable of type Int
- x is undefined
- x is a constant
- x has no type
var items = ["a":1, "b":2, "c":"test"] as [String: Any]
items["c"] = nil
print(items["c"] as Any)
- Any
- test
- 1,2,3
- nil
let val = 5.0 + 10
- 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
struct Test{
var score: Int
var date: Date
}
- zero
- This code contains an error
- two
- Structs do not have initializers
let x = try? String.init("test")
print(x)
- nil
- Nothing - this code contains an error
- Optional("test")
- test
var vals = [1,2,3]
-
vals.sort { $0 < $1 }
-
vals.sort { (s1, s2) in s1 < s2 }
-
vals.sort(by: <)
- all of these answers
- not executed
- executed in the main queue
- none of these answers
- executed on the background thread
- 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
- String?
- Optional[String]
- [String]?
- ?String
for i in ["0", "1"]{
print(i)
}
- one
- two
- three
- This code does not compile
let names = ["Bear", "Tony", "Svante"]
print(names[1]+"Bear")
- 1Bear
- BearBear
- TonyBear
- Nothing, this code is invalid
let name: String?
- 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.
let i = 5
let val = i * 6.0
- This code is invalid.
- 6
- 30
- 0
enum Positions : Int {
case first, second, third, other
}
print (Positions.other.rawValue)
- 3
- 0
- other
- nil
"t".forEach { (char) in
print(char)
}
- nil
- Nothing, since the code contains an error
- t
- zero
let s1 = ["1", "2", "3"]
.filter { $0 > "0" }
.sorted { $0 > $1 }
print(s1)
- []
- ["3", "2", "1"]
- [321]
- ["1", "2", "3"]
(Question does not make that much sense though. )
- associated values
- integral values
- raw values
- custom values
class AmP : MMM, AOM {
}
- class
- protocol
- enumeration
- struct
let numbers = [1,2,3,4,5,6].filter{ $0 % 2 == 0}
- [1,3,5]
- []
- [2,4,6]
- nil