Swift

What is this code an example of?

swift let val = (Double)6

1.

a syntax issue

2.

typecasting

3.

assignment

4.

initialization

Q 1 / 68

Swift

What is the error in this code?

swift let x = 5 guard x == 5 { return }

1.

The guard is missing the else.

2.

Nothing is wrong.

3.

The guard is missing a then.

4.

The comparison is wrong.

Q 2 / 68

Swift

What is the raw/underlying type of this enum?

swift enum Direction { case north, south, east, west }

1.

There is none.

2.

String

3.

Any

4.

Int

Q 3 / 68

Swift

Why is dispatchGroup used in certain situations?

1.

It allows multiple synchronous or asynchronous operations to run on different queues.

2.

It allows track and control execution of multiple operations together.

3.

It allows operations to wait for each other as desired.

4.

all of these answers.

Q 4 / 68

Swift

What is this code an example of?

swift let val = 5 print("value is: (val)")

1.

string interpolation

2.

string compilation

3.

method chaining

4.

string concatenation

Q 5 / 68

Swift

What are the contents of `vals` after this code is executed?

swift var vals = [10, 2] vals.sort { (s1, s2) -> Bool in s1 > s2 }

1.

[10, 2]

2.

[2, 10]

3.

nil

4.

This code contains an error

Q 6 / 68

Swift

What does this code print?

swift typealias Thing = [String:Any] var stuff: Thing print(type(of: stuff))

1.

Dictionary<String, Any>

2.

Dictionary

3.

ERROR

4.

Thing

Q 7 / 68

Swift

What is the value of y?

swift let x = ["1", "2"].dropFirst() let y = x[0]

1.

This code contains an error

2.

1

3.

2

4.

nil

Q 8 / 68

Swift

What is the value of test in this code?

swift var test = 1 == 1

1.

TRUE

2.

YES

3.

1

4.

This code contains an error

Q 9 / 68

Swift

What is the value of y?

swift var x: Int? let y = x ?? 5

1.

5

2.

0

3.

nil

4.

This code contains an error

Q 10 / 68

Swift

What is the type of this function?

swift func add(a: Int, b: Int) -> Int { return a+b }

1.

Int

2.

(Int, Int) -> Int

3.

Int<Optional>

4.

Functions don't have types.

Q 11 / 68

Swift

What is the correct way to call this function?

swift func myFunc(_ a: Int, b: Int) -> Int { return a + b }

1.

myFunc(5, b: 6)

2.

myFunc(5, 6)

3.

myFunc(a: 5, b: 6)

4.

myFunc(a, b)

Q 12 / 68

Swift

The Codable protocol is **_**?

1.

a combination of Encodable and Decodable

2.

not a true protocol <<<<---Possibly correct as it's a typealias of Encodable and Decodable

3.

required of all classes

4.

automatically included in all classes

Q 13 / 68

Swift

What is the type of value1 in this code?

swift let value1 = "("test".count)"

1.

String

2.

Int

3.

null

4.

test.count

Q 14 / 68

Swift

When a function takes a closure as a parameter, when do you want to mark is as escaping?

1.

when it's executed after the function returns

2.

when it's scope is undefined

3.

when it's lazy loaded

4.

all of these answers

Q 15 / 68

Swift

What's wrong with this code?

swift class Person { var name: String var address: String }

1.

Person has no initializers.

2.

Person has no base class.

3.

var name is not formatted corrrectly.

4.

address is a keyword.

Q 16 / 68

Swift

What is the value of names after this code is executed?

swift let names = ["Bear", "Joe", "Clark"] names.map { (s) -> String in return s.uppercased() }

1.

["BEAR", "JOE", "CLARK"]

2.

["B", "J", "C"]

3.

["Bear", "Joe", "Clark"]

4.

This code contains an error.

Q 17 / 68

Swift

What describes this line of code?

swift let val = 5

1.

a constant named val of type Int

2.

a variable named val of type item

3.

a constant named val of type Number

4.

a variable named val of type Int

Q 18 / 68

Swift

What is the error in this code?

swift extension String { var firstLetter: Character = "c" { didSet { print("new value") } } }

1.

Extensions can't add properties. // although extensions technically can't contain stored properties

2.

Nothing is wrong with it.

3.

didSet takes a parameter.

4.

c is not a character.

Q 19 / 68

Swift

didSet and willSet are examples of **_**?

1.

property observers

2.

key properties

3.

all of these answers

4.

newOld value calls

Q 20 / 68

Swift

What is wrong with this code?

swift self.callback = { self.attempts += 1 self.downloadFailed() }

1.

Use of self inside the closure causes retain cycle.

2.

You cannot assign a value to closure in this manner.

3.

You need to define the type of closure explicitly.

4.

There is nothing wrong with this code.

Q 21 / 68

Swift

How many values does vals have after this code is executed?

swift var vals = Set<String> = ["4", "5", "6"] vals.insert("5")

1.

three

2.

four

3.

eight

4.

This code contains an error.

Q 22 / 68

Swift

How can you avoid a strong reference cycle in a closure?

1.

Use a capture list to set class instances of weak or unowned.

2.

You can't, there will always be a danger of strong reference cycles inside a closure.

3.

Initialize the closure as read-only.

4.

Declare the closure variable as lazy.

Q 23 / 68

Swift

What is wrong with this code?

swift if let s = String.init("some string") { print(s) }

1.

This String initializer does not return an optional.

2.

String does not have an initializer that can take a String.

3.

= is not a comparison.

4.

Nothing is wrong with this code.

Q 24 / 68

Swift

Which code snippet correctly creates a typealias closure?

1.

typealias CustomClosure: () -> ()

2.

typealias CustomClosure { () -> () }

3.

typealias CustomClosure -> () -> ()

4.

typealias CustomClosure -> () {}

Q 25 / 68

Swift

How do you reference class members from within a class?

1.

self

2.

instance

3.

class

4.

this

Q 26 / 68

Swift

All value types in Swift are **_** under the hood?

1.

structs

2.

classes

3.

optionals

4.

generics

Q 27 / 68

Swift

What is the correct way to add a value to this array?

swift var strings = [1, 2, 3]

1.

all of these answers

2.

strings.append(4)

3.

strings.insert(5, at: 1)

4.

strings += [5]

Q 28 / 68

Swift

How many times will this loop be executed?

swift for i in 0...100 { print(i) }

1.

0

2.

101

3.

99

4.

100

Q 29 / 68

Swift

What can AnyObject represent?

1.

an instance of any class

2.

an instance of function type

3.

all of these answers

4.

an instance of an optional type

Q 30 / 68

Swift

What does this code print?

swift typealias Thing = [String:Any] var stuff : Thing print(type(of:stuff))

1.

Dictionary

2.

ERROR

3.

Thing

4.

Dictionary<String, Any>

Q 31 / 68

Swift

What is the value of t after this code is executed?

swift let names = ["Larry", "Sven", "Bear"] let t = names.enumerated().first().offset

1.

This code is invalid.

2.

This code does not compile.

3.

0

4.

1

5.

Larry

Q 32 / 68

Swift

undefined

swift let vt = (name: "ABC", val: 5) let test = vt.0

1.

ABC

2.

0

3.

5

4.

name

Q 33 / 68

Swift

undefined

swift class LSN : MMM { }

1.

MMM

2.

LSN

3.

There is no base class.

4.

This code is invalid.

Q 34 / 68

Swift

undefined

swift 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"

1.

About to set userLocation to Work… userLocation updated with new value!

2.

About to set userLocation to Work… userLocation already set to that value…

3.

About to set userLocation to Home… userLocation updated to new value!

4.

ERROR

Q 35 / 68

Swift

undefined

1.

a base class convenience initializer

2.

either a designated or another convenience initializer

3.

a designated initializer

4.

none of these answers

Q 36 / 68

Swift

undefined

1.

DispatchQueue.visible

2.

DispatchQueue.global

3.

errorExample need to be labeled as `throws`.

4.

DispatchQueue.background

Q 37 / 68

Swift

undefined

swift let x = ["a", "b", "c"]

1.

`String[]`

2.

`Array<String>`

3.

`Set<String>`

4.

`Array<Character>`

Q 38 / 68

Swift

undefined

swift let nThings: [Any] = [1, "2", "three"] let oThings = nThings.reduce("") { "($0)($1)" }

1.

11212three

2.

115

3.

12three

4.

Nothing, this code is invalid.

Q 39 / 68

Swift

undefined

1.

`!try`

2.

`try?`

3.

`try!`

4.

`?try`

Q 40 / 68

Swift

undefined

swift protocol TUI { func add(x1 : Int, x2 : Int) -> Int { return x1 + x2 } }

1.

Protocol functions cannot have return types.

2.

Protocol functions cannot have implementations.

3.

Nothing is wrong with it.

4.

`add` is a reserved keyword.

Q 41 / 68

Swift

undefined

swift class Car { var wheels: Int = 4 let doors = 4 }

1.

class members

2.

This code is invalid.

3.

class fields

4.

class properties

Q 42 / 68

Swift

undefined

1.

You cannot

2.

deinit

3.

`init?`

4.

init

Q 43 / 68

Swift

undefined

swift let dbl = Double.init("5a") print(dbl ?? ".asString()")

1.

five

2.

5a

3.

`.asString()`

4.

5

Q 44 / 68

Swift

undefined

swift func add(this x: Int, toThat y: Int)->{}

1.

none of these answers

2.

local terms

3.

argument labels

4.

parameters names

Q 45 / 68

Swift

undefined

swift for (key, value) in [1: "one", 2: "two"]{ print(key, value) }

1.

The interaction source is invalid

2.

The interaction variable is invalid

3.

There is nothing wrong with this code

4.

The comma in the print is misplaced

Q 46 / 68

Swift

undefined

1.

XCTest

2.

all of these answers

3.

@testable

4.

XCAssert

Q 47 / 68

Swift

undefined

swift class Square{ var height: Int = 0 var width : Int { return height } }

1.

This code contains error

2.

a closure

3.

a computed property

4.

lazy loading

Q 48 / 68

Swift

undefined

swift let vals = ("val", 1)

1.

a dictionary

2.

a tuple

3.

an optional

4.

This code contains error

Q 49 / 68

Swift

undefined

swift var x = 5 x = 10.0

1.

You cannot assign a Double to a variable of type Int

2.

x is undefined

3.

x is a constant

4.

x has no type

Q 50 / 68

Swift

undefined

swift var items = ["a":1, "b":2, "c":"test"] as [String: Any] items["c"] = nil print(items["c"] as Any)

1.

Any

2.

test

3.

1,2,3

4.

nil

Q 51 / 68

Swift

undefined

swift let val = 5.0 + 10

1.

There is nothing wrong with this code

2.

val is a constant and cannot be changed

3.

5.0 and 10 are different types

4.

There is no semicolon

Q 52 / 68

Swift

undefined

swift struct Test{ var score: Int var date: Date }

1.

zero

2.

This code contains an error

3.

two

4.

Structs do not have initializers

Q 53 / 68

Swift

undefined

swift let x = try? String.init("test") print(x)

1.

nil

2.

Nothing - this code contains an error

3.

Optional("test")

4.

test

Q 54 / 68

Swift

undefined

swift var vals = [1,2,3]

1.

`vals.sort { $0 < $1 }`

2.

`vals.sort { (s1, s2) in s1 < s2 }`

3.

`vals.sort(by: <)`

4.

all of these answers

Q 55 / 68

Swift

undefined

1.

not executed

2.

executed in the main queue

3.

none of these answers

4.

executed on the background thread

Q 56 / 68

Swift

undefined

1.

When a class instance needs memory

2.

All of these answers

3.

When the executable code is finished

4.

When a class instance is being removed from memory

Q 57 / 68

Swift

undefined

1.

String?

2.

Optional[String]

3.

[String]?

4.

?String

Q 58 / 68

Swift

undefined

swift for i in ["0", "1"]{ print(i) }

1.

one

2.

two

3.

three

4.

This code does not compile

Q 59 / 68

Swift

undefined

swift let names = ["Bear", "Tony", "Svante"] print(names[1]+"Bear")

1.

1Bear

2.

BearBear

3.

TonyBear

4.

Nothing, this code is invalid

Q 60 / 68

Swift

undefined

swift let name: String?

1.

name can hold only a string value.

2.

name can hold either a string or nil value.

3.

Optional values cannot be `let` constants.

4.

Only non-empty string variables can be stored in name.

Q 61 / 68

Swift

undefined

swift let i = 5 let val = i * 6.0

1.

This code is invalid.

2.

6

3.

30

4.

0

Q 62 / 68

Swift

undefined

swift enum Positions : Int { case first, second, third, other } print (Positions.other.rawValue)

1.

3

2.

0

3.

other

4.

nil

Q 63 / 68

Swift

undefined

swift "t".forEach { (char) in print(char) }

1.

nil

2.

Nothing, since the code contains an error

3.

t

4.

zero

Q 64 / 68

Swift

undefined

swift let s1 = ["1", "2", "3"] .filter { $0 > "0" } .sorted { $0 > $1 } print(s1)

1.

[]

2.

["3", "2", "1"]

3.

[321]

4.

["1", "2", "3"]

Q 65 / 68

Swift

undefined

(Question does not make that much sense though. )

1.

associated values

2.

integral values

3.

raw values

4.

custom values

Q 66 / 68

Swift

undefined

swift class AmP : MMM, AOM { }

1.

class

2.

protocol

3.

enumeration

4.

struct

Q 67 / 68

Swift

undefined

swift let numbers = [1,2,3,4,5,6].filter{ $0 % 2 == 0}

1.

[1,3,5]

2.

[]

3.

[2,4,6]

4.

nil

Q 68 / 68