Swift (iOs) MCQs with answers Page - 16

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 of these is a correct use of a for-in loop?

  • (A) for 0 to 5 { print(i) }
  • (B) foreach i in 0...5 { print(i) }
  • (C) for i in 0...5 { print(i) }
  • (D) loop i = 0 to 5 { print(i) }

A

Admin • 828.03K Points
Coach

Q. Which of these methods reverses an array in-place?

  • (A) reversed()
  • (B) reverse()
  • (C) flip()
  • (D) mirror()

A

Admin • 828.03K Points
Coach

Q. What will be the type of `let value = (404, "Not Found")`?

  • (A) (Int, String)
  • (B) [Int: String]
  • (C) Dictionary
  • (D) Tuple

A

Admin • 828.03K Points
Coach

Q. How do you access the number of items in a Dictionary?

  • (A) count()
  • (B) length
  • (C) size()
  • (D) count

A

Admin • 828.03K Points
Coach

Q. Which function would you use to check if an array contains a value?

  • (A) has()
  • (B) contains()
  • (C) includes()
  • (D) exists()

A

Admin • 828.03K Points
Coach

Q. What will this code print?

Code:
let optionalName: String? = "Swift"
if let name = optionalName {
 print(name) }
  • (A) Swift
  • (B) Optional("Swift")
  • (C) name
  • (D) Error

A

Admin • 828.03K Points
Coach

Q. Which Swift keyword is used to indicate a throwing function?

  • (A) throw
  • (B) throws
  • (C) try
  • (D) catch

A

Admin • 828.03K Points
Coach

Q. What is a correct way to declare a Swift enum?

  • (A) enum Colors: String { case red, green, blue }
  • (B) enum Colors { red, green, blue }
  • (C) enum Colors [red, green, blue]
  • (D) enum Colors => red, green, blue

A

Admin • 828.03K Points
Coach

Q. What does the `stride(from:to:by:)` function do in Swift?

  • (A) Generates a random number
  • (B) Iterates over a range with a specific step size
  • (C) Sorts an array
  • (D) Returns the largest number

A

Admin • 828.03K Points
Coach

Q. What is the result of this code?

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

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