Swift (iOs) MCQs with answers Page - 1

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

R

Ravina • 3.59K Points
Extraordinary

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

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

R

Ravina • 3.59K Points
Extraordinary

Q. What does the following Swift code print?

Code:
let name: String? = nil
print(name ?? "Unknown")
  • (A) nil
  • (B) Unknown
  • (C) name
  • (D) Optional("Unknown")

R

Ravina • 3.59K Points
Extraordinary

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

  • (A) function
  • (B) define
  • (C) func
  • (D) fn

R

Ravina • 3.59K Points
Extraordinary

Q. What is the output of the following code?

Code:
let numbers = [1, 2, 3]
print(numbers[1])
  • (A) 1
  • (B) 2
  • (C) 3
  • (D) Index out of range

R

Ravina • 3.59K Points
Extraordinary

Q. What is the purpose of optionals in Swift?

  • (A) To store functions
  • (B) To allow nil values safely
  • (C) To define immutable data
  • (D) To increase performance

R

Ravina • 3.59K Points
Extraordinary

Q. How do you unwrap an optional safely in Swift?

  • (A) Using * operator
  • (B) Using if let
  • (C) Using guard var
  • (D) Using throw

R

Ravina • 3.59K Points
Extraordinary

Q. Which collection type in Swift does not allow duplicate values?

  • (A) Array
  • (B) Set
  • (C) Dictionary
  • (D) Tuple

R

Ravina • 3.59K Points
Extraordinary

Q. What is the result of this code?

Code:
let result = 10 / 3
print(result)
  • (A) 3.333
  • (B) 3.0
  • (C) 3
  • (D) Error

R

Ravina • 3.59K Points
Extraordinary

Q. Which operator is used for optional chaining in Swift?

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

R

Ravina • 3.59K Points
Extraordinary

Q. What will this code print?

Code:
var x = 5
x += 1
print(x)
  • (A) 5
  • (B) 6
  • (C) Error
  • (D) 1

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