Swift (iOs) MCQs with answers Page - 17

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 • 828.03K Points
Coach

Q. Which operator is used to unwrap an optional value forcibly?

  • (A) ??
  • (B) !
  • (C) ->
  • (D) as!

A

Admin • 828.03K Points
Coach

Q. What does `@Binding` do in SwiftUI?

  • (A) Passes a copy of a variable
  • (B) Creates a shared reference to a state variable
  • (C) Creates a local variable
  • (D) Creates a computed property

A

Admin • 828.03K Points
Coach

Q. What will this code print?

Code:
var x = 10
x += 5
print(x)
  • (A) 5
  • (B) 10
  • (C) 15
  • (D) 20

A

Admin • 828.03K Points
Coach

Q. Which of the following defines a dictionary in Swift?

  • (A) let dict = ["key": "value"]
  • (B) let dict = ("key", "value")
  • (C) let dict = {key: value}
  • (D) let dict = ["key" -> "value"]

A

Admin • 828.03K Points
Coach

Q. Which keyword defines a protocol in Swift?

  • (A) interface
  • (B) contract
  • (C) protocol
  • (D) abstract

A

Admin • 828.03K Points
Coach

Q. What is the result of this code?

Code:
let values = [1, 2, 3]
print(values.map { $0 * 2 })
  • (A) [1, 2, 3]
  • (B) [2, 4, 6]
  • (C) [0, 2, 4]
  • (D) [1, 4, 9]

A

Admin • 828.03K Points
Coach

Q. Which Swift keyword is used to declare an enumeration?

  • (A) class
  • (B) enum
  • (C) struct
  • (D) protocol

A

Admin • 828.03K Points
Coach

Q. Which Swift keyword is used to define a constant?

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

A

Admin • 828.03K Points
Coach

Q. What does `@Published` do in Swift?

  • (A) Creates an optional
  • (B) Allows observing changes in a property
  • (C) Marks a method for publication
  • (D) Creates a static value

A

Admin • 828.03K Points
Coach

Q. Which loop is used to execute code while a condition is true?

  • (A) for-in
  • (B) repeat
  • (C) while
  • (D) loop

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