Swift (iOs) MCQs with answers Page - 7

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. Which of the following keywords is used to define an enumeration in Swift?

  • (A) enum
  • (B) enumeration
  • (C) list
  • (D) case

A

Admin • 802.91K Points
Coach

Q. What will the following Swift code print?

Code:
let a = 4
let b = 2
debugPrint(a / b)
  • (A) 2
  • (B) 2.0
  • (C) 2.00
  • (D) Error

A

Admin • 802.91K Points
Coach

Q. Which of the following defines a function with no parameters and no return value in Swift?

  • (A) func hello() -> Void {}
  • (B) function hello {}
  • (C) def hello():
  • (D) void hello() {}

A

Admin • 802.91K Points
Coach

Q. What will the following Swift code output?

Code:
let temperature = 30
print(temperature >= 25 && temperature <= 35)
  • (A) true
  • (B) false
  • (C) nil
  • (D) Error

A

Admin • 802.91K Points
Coach

Q. How do you declare a variable in Swift that must always hold a value (non-optional)?

  • (A) let name: String?
  • (B) var name: String
  • (C) let name: Optional<String>
  • (D) var name: String?

A

Admin • 802.91K Points
Coach

Q. Which of the following methods appends a new element to a Swift array?

  • (A) add()
  • (B) insert()
  • (C) append()
  • (D) push()

A

Admin • 802.91K Points
Coach

Q. Which keyword is used to define a protocol in Swift?

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

A

Admin • 802.91K Points
Coach

Q. What is the correct way to unwrap an optional using `guard`?

  • (A) guard let value = optionalValue else { return }
  • (B) guard value = optionalValue ? else { return }
  • (C) guard optionalValue != nil else { return }
  • (D) if value = optionalValue else { return }

A

Admin • 802.91K Points
Coach

Q. Which of these is a value type in Swift?

  • (A) Class
  • (B) Struct
  • (C) Function
  • (D) Protocol

A

Admin • 802.91K Points
Coach

Q. What will the following code output?

Code:
let str = "Swift"
print(str.count)
  • (A) 4
  • (B) 5
  • (C) 6
  • (D) Error

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