Swift (iOs) MCQs with answers Page - 18

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 result = "swift".count
print(result)
  • (A) 4
  • (B) 5
  • (C) 6
  • (D) Error

A

Admin • 828.03K Points
Coach

Q. What does the `mutating` keyword do in Swift?

  • (A) Allows a struct method to modify its properties
  • (B) Makes a function constant
  • (C) Prevents changes to variables
  • (D) Enables inheritance

A

Admin • 828.03K Points
Coach

Q. What will this code print?

Code:
let value = "123"
let number = Int(value)
print(number ?? 0)
  • (A) 123
  • (B) Optional(123)
  • (C) 0
  • (D) nil

A

Admin • 828.03K Points
Coach

Q. Which method converts a string to uppercase in Swift?

  • (A) uppercase()
  • (B) toUpper()
  • (C) uppercased()
  • (D) capitalize()

A

Admin • 828.03K Points
Coach

Q. What does the `@discardableResult` attribute do?

  • (A) Ignores errors in a function
  • (B) Allows a function’s return value to be unused
  • (C) Suppresses compiler warnings
  • (D) Prevents unwrapping of optionals

A

Admin • 828.03K Points
Coach

Q. What is the purpose of `@objc` in Swift?

  • (A) Marks code for Objective-C compatibility
  • (B) Makes code run faster
  • (C) Optimizes memory
  • (D) Marks properties as optional

A

Admin • 828.03K Points
Coach

Q. What will this code print?

Code:
let numbers = [1, 2, 3, 4, 5]
print(numbers.dropFirst(2))
  • (A) [1, 2, 3, 4, 5]
  • (B) [3, 4, 5]
  • (C) [1, 2]
  • (D) [2, 3, 4, 5]

A

Admin • 828.03K Points
Coach

Q. Which of these types is not a value type in Swift?

  • (A) Struct
  • (B) Enum
  • (C) Class
  • (D) Tuple

R

Ravina • 3.96K Points
Extraordinary

Q. What does the `as?` operator do in Swift?

  • (A) Performs forced type casting
  • (B) Checks type only
  • (C) Performs conditional type casting
  • (D) Declares a variable

R

Ravina • 3.96K Points
Extraordinary

Q. Which method is used to remove all elements from an array?

  • (A) remove()
  • (B) clear()
  • (C) deleteAll()
  • (D) removeAll()

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