Swift MCQ: Swift Multiple Choice Questions and Answers

Swift MCQ with answers and explanations for placement tests and job interviews. These solved Swift MCQs are useful for the campus placement for all freshers including Engineering Students, MCA students, Computer and IT Engineers, etc.

Our Swift MCQ (Swift Multiple Choice Questions ) focuses on various parts of the Swift programming language and its concept. It will be useful for anyone learning Swift Basics, Essentials, and/or Fundamentals. We will regularly update the quiz and most interesting thing is that questions come in a random sequence. So every time you will feel new questions.

There are several Swift courses that you may have come across during your search for learning the Swift language. Our team of experts has carefully analyzed some Swift courses for you. You can check the courses, Trial of some courses is free.

 

Guideline of Swift MCQ:

This Swift MCQ is intended for checking your Swift programming knowledge. It takes 1 hour to pass the Swift MCQ. If you don’t finish the Swift MCQ within the mentioned time, all the unanswered questions will count as wrong. You can miss the questions by clicking the “Next” button and return to the previous questions by the “Previous” button. Every unanswered question will count as wrong. MCQ on Swift has features of randomization which feel you a new question set at every attempt.

In this Swift MCQ, we have also implemented a feature that not allowed the user to see the next question or finish the Swift quiz without attempting the current Swift MCQ.

6 votes, 4.2 avg

You have 1 hours to take the Swift MCQs

Your time has been Over.


Swift MCQ

Swift MCQ: Swift Multiple Choice Questions and Answers

1 / 64

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

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

 

2 / 64

What does this code print?

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

 

3 / 64

What does this code print?

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

 

4 / 64

What is wrong with this code?

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

 

5 / 64

What does this code print?

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

 

6 / 64

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

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

 

7 / 64

What is the value of y?

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

 

8 / 64

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

9 / 64

What is the error in this code?

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

 

10 / 64

What is the type of value1 in this code?

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

 

11 / 64

What can AnyObject represent?

12 / 64

What is printed when this code is executed?

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

 

13 / 64

What is this code an example of?

let val = (Double)6

 

14 / 64

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

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

 

15 / 64

When is deinit called?

16 / 64

What is the inferred type of x?

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

 

17 / 64

What is the correct way to call this function?

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

 

18 / 64

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)

 

19 / 64

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

var strings = [1, 2, 3]

 

20 / 64

How can you sort this array?

var vals = [1,2,3]

 

21 / 64

DispatchQueue.main.async takes a block that will be

22 / 64

Why is dispatchGroup used in certain situations?

23 / 64

Which of these choices is associated with unit testing?

24 / 64

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

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

 

25 / 64

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

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

 

26 / 64

What must a convenience initializer call?

27 / 64

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

let i = 5
let val = i * 6.0

 

28 / 64

What is wrong with this code?

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

 

29 / 64

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

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

 

30 / 64

What prints when this code is executed?

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

 

31 / 64

What does this code print?

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

 

32 / 64

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

33 / 64

How do you reference class members from within a class?

34 / 64

How do you declare an optional String?

35 / 64

What is the value of y?

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

 

36 / 64

What is this code an example of?

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

 

37 / 64

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

38 / 64

What is the value of test in this code?

var test = 1 == 1

 

39 / 64

What is wrong with this code?

var x = 5
x = 10.0

 

40 / 64

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

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

 

41 / 64

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

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

 

42 / 64

What's wrong with this code?

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

 

43 / 64

How many parameters does the initializer for Test have?

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

 

44 / 64

What is wrong with this code?

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

 

45 / 64

What is wrong with this code?

let val = 5.0 + 10

 

46 / 64

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"

 

47 / 64

What data type is this an example of?

let vals = ("val", 1)

 

48 / 64

What is the base class in this code?

class LSN : MMM {
}

 

49 / 64

What prints to the console when executing this code?

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

 

50 / 64

Which code snippet correctly creates a typealias closure?

51 / 64

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

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

 

52 / 64

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

53 / 64

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

54 / 64

What is the raw/underlying type of this enum?

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

 

55 / 64

How many times will this loop be executed?

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

 

56 / 64

What is true of this code?

let name: String?

 

57 / 64

What is the value of test after this code executes?

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

 

58 / 64

The Codable protocol is **_**?

 

59 / 64

How do you designated a failable initializer?

60 / 64

What is the type of this function?

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

 

61 / 64

What is the error in this code?

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

 

62 / 64

What describes this line of code?

let val = 5

 

63 / 64

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

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

 

64 / 64

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

Your score is

The average score is 0%

0%

Recommended Articles for you: