Swift (iOs) MCQs with answers Page - 6

Here, you will find a collection of MCQ questions on Swift (iOs). Go through these questions to enhance your preparation for upcoming examinations and interviews.

To check the correct answer, simply click the View Answer button provided for each question.

Have your own questions to contribute? Click the button below to share your MCQs with others!

+ Add Question

A

Admin • 802.91K Points
Coach

Q. What keyword is used to define a constant that can never change?

  • (A) var
  • (B) let
  • (C) final
  • (D) static

A

Admin • 802.91K Points
Coach

Q. Which of the following is used to define a closure in Swift?

  • (A) {}
  • (B) []
  • (C) ()->{}
  • (D) () => {}

A

Admin • 802.91K Points
Coach

Q. What will this Swift code output?

Code:
let numbers = [1, 2, 3, 4, 5]
let even = numbers.filter { $0 % 2 == 0 }
print(even)
  • (A) [1, 3, 5]
  • (B) [2, 4]
  • (C) [1, 2, 3, 4, 5]
  • (D) [0]

A

Admin • 802.91K Points
Coach

Q. Which statement is used to define a computed property?

  • (A) var name = value
  • (B) let name = { return value }
  • (C) var name: Type { return value }
  • (D) func name() -> Type

A

Admin • 802.91K Points
Coach

Q. What is the use of `defer` in Swift?

  • (A) To delay function call
  • (B) To define async code
  • (C) To schedule clean-up code to run before scope exit
  • (D) To pause execution

A

Admin • 802.91K Points
Coach

Q. What will the following code output?

Code:
let a = 10
let b = 20
print(a > b)
  • (A) true
  • (B) false
  • (C) nil
  • (D) error

A

Admin • 802.91K Points
Coach

Q. Which of these is a valid way to declare an empty string?

  • (A) var str = empty
  • (B) var str = nil
  • (C) var str = ""
  • (D) var str = String(0)

A

Admin • 802.91K Points
Coach

Q. What type does `Int.random(in: 1...5)` return?

  • (A) Array
  • (B) Int
  • (C) Float
  • (D) Bool

A

Admin • 802.91K Points
Coach

Q. What is the purpose of `optional binding` in Swift?

  • (A) To make a variable global
  • (B) To define a lazy property
  • (C) To safely unwrap an optional
  • (D) To create a loop

A

Admin • 802.91K Points
Coach

Q. Which of the following is true about Swift variables?

  • (A) `let` allows reassignment
  • (B) `var` allows changing values
  • (C) `const` is used for fixed values
  • (D) Variables must always be optional

Add MCQ in this Category

If you want to share an MCQ question in this category, it's a great idea! It will be helpful for many other students using this website.

Share Your MCQ