Swift (iOs) MCQs with answers Page - 15

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 • 833.24K Points
Coach

Q. What will the following code print?

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

A

Admin • 833.24K Points
Coach

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

  • (A) func add<T>(a: T, b: T) -> T
  • (B) function add<T>(T a, T b): T
  • (C) generic add(a, b): T
  • (D) func<T> add(a: T, b: T): T

A

Admin • 833.24K Points
Coach

Q. Which Swift data type represents a type with no value?

  • (A) Any
  • (B) Void
  • (C) Empty
  • (D) None

A

Admin • 833.24K Points
Coach

Q. What does `@main` do in Swift?

  • (A) Specifies the main view in SwiftUI
  • (B) Specifies the main function in a program
  • (C) Defines a main module
  • (D) Marks a test case

A

Admin • 833.24K Points
Coach

Q. What is the output of this code?

Code:
let array = [1, 2, 3, 4]
print(array[2])
  • (A) 2
  • (B) 3
  • (C) 4
  • (D) 1

A

Admin • 833.24K Points
Coach

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

  • (A) extends
  • (B) inherits
  • (C) subclass
  • (D) :

A

Admin • 833.24K Points
Coach

Q. What will this code print?

Code:
let str: String? = nil
print(str ?? "Default")
  • (A) nil
  • (B) Optional(nil)
  • (C) Default
  • (D) Error

A

Admin • 833.24K Points
Coach

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

  • (A) "Hello"
  • (B) true
  • (C) 3.14
  • (D) char

A

Admin • 833.24K Points
Coach

Q. How do you write a comment that spans multiple lines in Swift?

  • (A) // comment
  • (B) /* comment */
  • (C) # comment
  • (D) -- comment

A

Admin • 833.24K Points
Coach

Q. Which function returns the index of the first matching element?

  • (A) firstIndex(of:)
  • (B) indexOf()
  • (C) getIndex()
  • (D) find()