Discover the fundamentals of Swift programming with these 30 MCQs. Covering Swift’s basics, Xcode setup, programming paradigms, and first program creation, this guide simplifies your learning journey.
1. Introduction to Swift
What is Swift?
A) A scripting language
B) A programming language for iOS and macOS development
C) A markup language
D) A database query language
Which company developed Swift?
A) Google
B) Microsoft
C) Apple
D) IBM
What is the file extension for Swift source files?
A) .swift
B) .xcode
C) .sft
D) .code
Which of the following is a key feature of Swift?
A) Strongly typed
B) Type inference
C) Memory safety
D) All of the above
Swift replaced which programming language as the primary language for iOS development?
A) Java
B) Objective-C
C) C#
D) Kotlin
2. Setting up Xcode and Swift Playgrounds
What is Xcode primarily used for?
A) Database management
B) iOS and macOS application development
C) Web application development
D) Game development
Which platform supports Xcode?
A) Windows
B) Linux
C) macOS
D) All of the above
What is Swift Playgrounds designed for?
A) Writing SQL queries
B) Experimenting with Swift code interactively
C) Managing cloud servers
D) Debugging compiled applications
In Xcode, which file type is used to design user interfaces?
A) .swift
B) .storyboard
C) .playground
D) .ui
Which of the following can be achieved using Swift Playgrounds?
A) Building complete applications
B) Testing snippets of Swift code
C) Setting up production environments
D) Writing database schemas
3. Swift Programming Paradigms (Procedural, Object-Oriented, Functional)
Which of the following is a supported programming paradigm in Swift?
A) Procedural
B) Object-Oriented
C) Functional
D) All of the above
What is a key feature of object-oriented programming in Swift?
A) Functions
B) Classes and inheritance
C) Memory allocation
D) Iteration
In Swift, what is the primary benefit of functional programming?
A) Faster compilation
B) Stateless and predictable code behavior
C) Automatic memory management
D) Enhanced debugging tools
What does “immutable” mean in functional programming?
A) Code cannot compile
B) Variables cannot change after they are set
C) Functions cannot be reused
D) Memory cannot be allocated
Which Swift feature supports procedural programming?
A) Control flow statements like if, for, and while
B) Closures
C) Protocol-oriented design
D) All of the above
4. Writing Your First Swift Program
What is the entry point for a Swift program?
A) @main
B) func start()
C) void main()
D) initialize()
In Swift, which keyword is used to define a constant?
A) let
B) const
C) fixed
D) static
How do you declare a variable in Swift?
A) var
B) dim
C) declare
D) def
What is the correct way to print “Hello, World!” in Swift?
A) console.log("Hello, World!")
B) print("Hello, World!")
C) printf("Hello, World!")
D) echo "Hello, World!"
How is a single-line comment added in Swift?
A) //
B) #
C) /*
D) **
5. Swift Syntax and Features
Which symbol is used for string interpolation in Swift?
A) $
B) %
C) #
D) \()
What is the purpose of the guard statement in Swift?
A) To catch exceptions
B) To conditionally execute code
C) To exit a function early if conditions are not met
D) To create loops
Which Swift keyword is used to create a function?
A) method
B) function
C) func
D) define
In Swift, how is an optional value declared?
A) var x: Int?
B) optional Int x
C) int? x
D) x: optional Int
What happens if you try to access a nil optional without unwrapping it in Swift?
A) The program compiles without errors
B) A runtime error occurs
C) A compile-time error occurs
D) The optional is treated as zero
6. Debugging and Error Handling
Which keyword is used to handle errors in Swift?
A) try
B) catch
C) throw
D) All of the above
What is the purpose of the do-catch block in Swift?
A) To perform safe operations
B) To handle exceptions or errors
C) To define global variables
D) To manage memory
In Swift, what does the defer keyword do?
A) Executes code at the end of the scope
B) Pauses execution for debugging
C) Declares a delayed variable
D) Executes a function later
How are runtime errors handled in Swift?
A) Using guard statements
B) Using the try-catch block
C) Using optional chaining
D) Using assertions
What is the purpose of fatalError() in Swift?
A) To stop execution and provide a message
B) To gracefully exit the program
C) To debug code
D) To allocate resources
Answer Key
Qno
Answer (Option with Text)
1
B) A programming language for iOS and macOS development
2
C) Apple
3
A) .swift
4
D) All of the above
5
B) Objective-C
6
B) iOS and macOS application development
7
C) macOS
8
B) Experimenting with Swift code interactively
9
B) .storyboard
10
B) Testing snippets of Swift code
11
D) All of the above
12
B) Classes and inheritance
13
B) Stateless and predictable code behavior
14
B) Variables cannot change after they are set
15
A) Control flow statements like if, for, and while
16
A) @main
17
A) let
18
A) var
19
B) print("Hello, World!")
20
A) //
21
D) \()
22
C) To exit a function early if conditions are not met