30 Swift Quiz Questions and Answers

Swift is a general-purpose programming language developed by Apple Inc. It was introduced in 2014 as a replacement for Objective-C, the previous primary language used for iOS and macOS app development. Swift is designed to be safe, efficient, and modern, with a focus on developer productivity.

Pro Tip

Want to assess your learners online? Create an online quiz for free!

Table of content

Part 1: 30 Swift quiz questions & answers

1. Which company developed the Swift programming language?
a) Google
b) Microsoft
c) Apple (Answer)
d) IBM

2. When was Swift first introduced?
a) 2008
b) 2010
c) 2014 (Answer)
d) 2016

3. Swift is primarily used for developing applications for which operating systems?
a) iOS and macOS (Answer)
b) Windows and Android
c) Linux and Ubuntu
d) All of the above

4. What programming language did Swift replace as the primary language for iOS and macOS development?
a) Objective-C (Answer)
b) C++
c) Java
d) Python

5. Which of the following is a key feature of Swift that enhances code safety?
a) Automatic reference counting (ARC)
b) Optionals (Answer)
c) Closures
d) Protocol-oriented programming

6. Swift uses a technique called _______ to manage memory automatically.
a) Garbage collection
b) Automatic reference counting (ARC) (Answer)
c) Manual memory management
d) Dynamic memory allocation

7. Which keyword is used to define a constant in Swift?
a) let (Answer)
b) var
c) const
d) constant

8. What is the Swift equivalent of the “if-else” statement in other programming languages?
a) ifelse
b) ifthen
c) ifelseend
d) if-else (Answer)

9. Which operator is used for optional chaining in Swift?
a) ?
b) !
c) &
d) . (Answer)

10. What does the “guard” statement in Swift do?
a) Declares a new variable
b) Terminates the execution of a loop
c) Provides early exit from a function (Answer)
d) Declares a switch statement

11. What is the purpose of the “break” keyword in Swift?
a) Terminates the execution of a loop (Answer)
b) Skips the current iteration of a loop
c) Declares a switch statement
d) None of the above

12. Which type of loop in Swift is executed at least once, regardless of the condition?
a) for-in loop
b) while loop
c) repeat-while loop (Answer)
d) foreach loop

13. Which Swift collection type is ordered and allows duplicate elements?
a) Set
b) Dictionary
c) Array (Answer)
d) Tuple

14. Which keyword is used to define a function in Swift?
a) method
b) function (Answer)
c) def
d) proc

15. What does the “self” keyword refer to in Swift?
a) The current class or structure instance (Answer)
b) The parent class or superclass
c) The main function
d) The global scope

Part 2: Download Swift questions & answers for free

Download questions & answers for free

Download quiz questions
Generate questions for any topic

16. Which keyword is used to declare a subclass in Swift?
a) class
b) struct
c) sub (Answer)
d) inherit

17. Which Swift feature allows multiple values to be returned from a function?
a) Closures
b) Optionals
c) Tuples (Answer)
d) Extensions

18. What is the purpose of the “defer” keyword in Swift?
a) Delays the execution of a code block until the end of the current scope (Answer)
b) Skips the current iteration of a loop
c) Terminates the execution of a loop
d) Declares a switch statement

19. Which Swift keyword is used to handle errors?
a) catch
b) throw
c) do
d) try (Answer)

20. What is the purpose of the “lazy” keyword in Swift?
a) Defers the initialization of a property until its first access (Answer)
b) Specifies a property as constant
c) Marks a property as optional
d) Declares a computed property

21. Which Swift feature is used to define blueprints for creating objects?
a) Protocols (Answer)
b) Extensions
c) Generics
d) Type casting

22. Which Swift operator is used for pattern matching?
a) =
b) ==
c) ===
d) ~= (Answer)

23. Which keyword is used to mark a class or method as final in Swift?
a) static
b) final (Answer)
c) sealed
d) end

24. What is the purpose of the “associatedtype” keyword in Swift?
a) Declares a new typealias
b) Marks a type as optional
c) Defines an associated type within a protocol (Answer)
d) Specifies an alias for a generic type parameter

25. Which Swift feature allows operators and functions to work with different types?
a) Overloading
b) Type inference
c) Generics (Answer)
d) Dynamic dispatch

26. What is the Swift equivalent of a struct in other programming languages?
a) Object
b) Class
c) Instance
d) Structure (Answer)

Just so you know

With OnlineExamMaker quiz software, anyone can create & share professional online assessments easily.

27. Which Swift feature enables defining additional functionality to existing types?
a) Subclassing
b) Extensions (Answer)
c) Overriding
d) Inheritance

28. What is the purpose of the “mutating” keyword in Swift?
a) Marks a property as mutable
b) Enables a method to modify the instance it is called on (Answer)
c) Declares a computed property
d) Specifies a method as optional

29. Which Swift feature provides a way to handle collections of optional values?
a) Optional binding
b) Optional chaining
c) Nil coalescing operator
d) Optional unwrapping (Answer)

30. Which Swift feature allows custom operators to be defined and used?
a) Operator overloading
b) Operator precedence
c) Operator associativity
d) Custom operators (Answer)

Part 3: Free online quiz creator – OnlineExamMaker

Save time and effort with automated grading, instantly generating scores and results for each respondent. OnlineExamMaker grades your quizzes automatically, and provides valuable insights for performance evaluation. Whether you are an educator looking to engage students or a business professional seeking effective training methods, OnlineExamMaker quiz maker is a reliable and efficient solution that streamlines the assessment process for improved learning outcomes.

Create Your Next Quiz/Exam with OnlineExamMaker

SAAS, free forever
100% data ownership