Swift (iOs) MCQs with answers Page - 13

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 code print?

Code:
let a = [1, 2, 3, 4, 5]
let result = a.reduce(0, +)
print(result)
  • (A) 15
  • (B) 120
  • (C) 5
  • (D) 10

A

Admin • 828.03K Points
Coach

Q. What is the purpose of `deinit` in a Swift class?

  • (A) To initialize properties
  • (B) To free memory when the object is deallocated
  • (C) To override a method
  • (D) To inherit from another class

A

Admin • 828.03K Points
Coach

Q. Which keyword is used to handle potential errors in Swift?

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

A

Admin • 828.03K Points
Coach

Q. Which property wrapper is used for dependency injection in SwiftUI?

  • (A) @ObservedObject
  • (B) @State
  • (C) @EnvironmentObject
  • (D) @Binding

A

Admin • 828.03K Points
Coach

Q. Which of the following can be used to unwrap an optional if it contains a value?

  • (A) !
  • (B) ??
  • (C) guard let
  • (D) All of the above

A

Admin • 828.03K Points
Coach

Q. Which of the following is true about structs in Swift?

  • (A) Structs support inheritance
  • (B) Structs are passed by reference
  • (C) Structs are value types
  • (D) Structs can have deinit methods

A

Admin • 828.03K Points
Coach

Q. What is the type of the value returned by `UUID().uuidString`?

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

A

Admin • 828.03K Points
Coach

Q. What does the `compactMap` function do?

  • (A) Filters and returns all values
  • (B) Converts values to optional
  • (C) Filters out nils and unwraps non-nil values
  • (D) Reverses an array

A

Admin • 828.03K Points
Coach

Q. What will this code output?

Code:
let x = 2.5
print(Int(x))
  • (A) 2
  • (B) 3
  • (C) 2.5
  • (D) Error

A

Admin • 828.03K Points
Coach

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

  • (A) { (x: Int) -> Int in return x * x }
  • (B) function(x) { return x * x }
  • (C) [x: Int] => x * x
  • (D) (x) -> x * x

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