Swift (iOs) MCQs with answers Page - 5

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. What will this Swift code print?

Code:
let greeting = "Hello"
print(greeting.hasPrefix("He"))
  • (A) true
  • (B) false
  • (C) He
  • (D) Hello

A

Admin • 828.03K Points
Coach

Q. What is the result of the following code?

Code:
let a = 5
let b = 2
let result = a % b
print(result)
  • (A) 2
  • (B) 0
  • (C) 1
  • (D) 5

A

Admin • 828.03K Points
Coach

Q. Which of the following is used to define an infinite loop in Swift?

  • (A) while true
  • (B) loop forever
  • (C) do while(true)
  • (D) repeat forever

A

Admin • 828.03K Points
Coach

Q. Which of these is the correct syntax for a for-in loop in Swift?

  • (A) for i = 0 to 10
  • (B) foreach i in 0...10
  • (C) for i in 0...10
  • (D) loop i from 0 to 10

A

Admin • 828.03K Points
Coach

Q. What does the `is` operator check in Swift?

  • (A) Identity
  • (B) Equality
  • (C) Type checking
  • (D) Value comparison

A

Admin • 828.03K Points
Coach

Q. Which keyword is used to declare a subclass in Swift?

  • (A) inherits
  • (B) extends
  • (C) subclass
  • (D) class Subclass: Superclass

A

Admin • 828.03K Points
Coach

Q. How can you check if an optional contains a value?

  • (A) optional != 0
  • (B) optional != nil
  • (C) optional.exists
  • (D) optional.hasValue()

A

Admin • 828.03K Points
Coach

Q. Which of these is NOT a valid Swift loop?

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

A

Admin • 828.03K Points
Coach

Q. What will this code output?

Code:
let age = 18
print(age >= 18 ? "Adult" : "Minor")
  • (A) Adult
  • (B) Minor
  • (C) true
  • (D) false

A

Admin • 828.03K Points
Coach

Q. Which operator is used to unwrap an optional forcefully?

  • (A) ?
  • (B) !
  • (C) ?.
  • (D) ??

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