linkedin-skill-assessments-quizzes

Swift

Q1. What is this code an example of?

let val = (Double)6

Q2. What is the error in this code?

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

Q3. What is the raw/underlying type of this enum?

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

Q4. Why is dispatchGroup used in certain situations?

Q5. What is this code an example of?

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

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

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

Q7. What does this code print?

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

Q8. What is the value of y?

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

Q9. What is the value of test in this code?

var test = 1 == 1

Q10. What is the value of y?

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

Q11. What is the type of this function?

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

Q12. What is the correct way to call this function?

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

Q13. The Codable protocol is **_**?

Q14. What is the type of value1 in this code?

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

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

Q16. What’s wrong with this code?

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

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

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

Q18. What describes this line of code?

let val = 5

Q19. What is the error in this code?

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

Q20. didSet and willSet are examples of \***\*\_\*\***?

Q21. What is wrong with this code?

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

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

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

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

Q24. What is wrong with this code?

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

Q25. Which code snippet correctly creates a typealias closure?

Q26. How do you reference class members from within a class?

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

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

var strings = [1, 2, 3]

Q29. How many times will this loop be executed?

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

Q30. What can AnyObject represent?

Q31. What does this code print?

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

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

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

Q32. What is the value of test after this code executes?

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

Q33. What is the base class in this code?

class LSN : MMM {
}

Q34. 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"

Q35. What must a convenience initializer call?

Q36. Which object allows you access to specify that a block of code runs in a background thread?

Q37. What is the inferred type of x?

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

Q38. What is the value of oThings after this code is executed?

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

Q39. How would you call a function that throws errors and also returns a value?

Q40. What is wrong with this code?

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

Q41. In this code, what are wheels and doors examples of?

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

Q42. How do you designated a failable initializer?

Q43. What is printed when this code is executed?

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

Q44. In the function below, what are this and toThat examples of?

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

Q45. What is wrong with this code?

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

Q46. Which of these choices is associated with unit testing?

Q47. In the code below, what is width an example of?

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

Q48. What data type is this an example of?

let vals = ("val", 1)

Q49. What is wrong with this code?

var x = 5
x = 10.0

Q50. What will this code print to the console?

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

Q51. What is wrong with this code?

let val = 5.0 + 10

Q52. How many parameters does the initializer for Test have?

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

Q53. What prints to the console when executing this code?

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

Q54. How can you sort this array?

var vals = [1,2,3]

Q55. DispatchQueue.main.async takes a block that will be

Q56. When is deinit called?

Q57. How do you declare an optional String?

Q58. How many times this code will be executed? —OR— How many times will this loop be performed?

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

Q59. What does this code print?

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

Q60. What is true of this code?

let name: String?

Q61. What is the value of val after this code is executed?

let i = 5
let val = i * 6.0

Q62. What does this code print?

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

Q63. What is printed to the console when this code is executed?

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

Q64. What prints when this code is executed?

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