Swift (iOs) MCQs with answers Page - 4

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.96K Points
Extraordinary

Q. What is the output of the code below?

Code:
let str = "Hello"
print(str.uppercased())
  • (A) hello
  • (B) HELLO
  • (C) Hello
  • (D) error

R

Ravina • 3.96K Points
Extraordinary

Q. Which of the following is a correct way to define an enum in Swift?

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

R

Ravina • 3.96K Points
Extraordinary

Q. What is the default value of an optional variable in Swift?

  • (A) null
  • (B) nil
  • (C) 0
  • (D) undefined

R

Ravina • 3.96K Points
Extraordinary

Q. Which Swift keyword is used to inherit from a superclass?

  • (A) implements
  • (B) inherits
  • (C) extends
  • (D) override

R

Ravina • 3.96K Points
Extraordinary

Q. Which of the following represents a computed property in Swift?

  • (A) var area = width * height
  • (B) let area = width * height
  • (C) var area: Int { return width * height }
  • (D) func area() -> Int

R

Ravina • 3.96K Points
Extraordinary

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

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

R

Ravina • 3.96K Points
Extraordinary

Q. What will this code output?

Code:
let name = "Swift"
for char in name {
 print(char)
}
  • (A) S w i f t
  • (B) Swift
  • (C) Each character on a new line
  • (D) Error

R

Ravina • 3.96K Points
Extraordinary

Q. What is the purpose of the `lazy` keyword in Swift?

  • (A) To delay initialization until first use
  • (B) To create optional properties
  • (C) To mark properties as final
  • (D) To improve performance by skipping values

R

Ravina • 3.96K Points
Extraordinary

Q. What is true about closures in Swift?

  • (A) They are used only inside loops
  • (B) They are reference types
  • (C) They cannot capture variables
  • (D) They don’t support return values

R

Ravina • 3.96K Points
Extraordinary

Q. Which of the following is NOT a Swift data type?

  • (A) String
  • (B) Int
  • (C) Real
  • (D) Bool

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