MCQs on Getting Started with Swift | Swift

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

  1. 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
  2. Which company developed Swift?
    • A) Google
    • B) Microsoft
    • C) Apple
    • D) IBM
  3. What is the file extension for Swift source files?
    • A) .swift
    • B) .xcode
    • C) .sft
    • D) .code
  4. Which of the following is a key feature of Swift?
    • A) Strongly typed
    • B) Type inference
    • C) Memory safety
    • D) All of the above
  5. 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

  1. What is Xcode primarily used for?
    • A) Database management
    • B) iOS and macOS application development
    • C) Web application development
    • D) Game development
  2. Which platform supports Xcode?
    • A) Windows
    • B) Linux
    • C) macOS
    • D) All of the above
  3. What is Swift Playgrounds designed for?
    • A) Writing SQL queries
    • B) Experimenting with Swift code interactively
    • C) Managing cloud servers
    • D) Debugging compiled applications
  4. In Xcode, which file type is used to design user interfaces?
    • A) .swift
    • B) .storyboard
    • C) .playground
    • D) .ui
  5. 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)

  1. Which of the following is a supported programming paradigm in Swift?
    • A) Procedural
    • B) Object-Oriented
    • C) Functional
    • D) All of the above
  2. What is a key feature of object-oriented programming in Swift?
    • A) Functions
    • B) Classes and inheritance
    • C) Memory allocation
    • D) Iteration
  3. 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
  4. 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
  5. 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

  1. What is the entry point for a Swift program?
    • A) @main
    • B) func start()
    • C) void main()
    • D) initialize()
  2. In Swift, which keyword is used to define a constant?
    • A) let
    • B) const
    • C) fixed
    • D) static
  3. How do you declare a variable in Swift?
    • A) var
    • B) dim
    • C) declare
    • D) def
  4. 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!"
  5. How is a single-line comment added in Swift?
    • A) //
    • B) #
    • C) /*
    • D) **

5. Swift Syntax and Features

  1. Which symbol is used for string interpolation in Swift?
    • A) $
    • B) %
    • C) #
    • D) \()
  2. 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
  3. Which Swift keyword is used to create a function?
    • A) method
    • B) function
    • C) func
    • D) define
  4. In Swift, how is an optional value declared?
    • A) var x: Int?
    • B) optional Int x
    • C) int? x
    • D) x: optional Int
  5. 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

  1. Which keyword is used to handle errors in Swift?
    • A) try
    • B) catch
    • C) throw
    • D) All of the above
  2. 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
  3. 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
  4. How are runtime errors handled in Swift?
    • A) Using guard statements
    • B) Using the try-catch block
    • C) Using optional chaining
    • D) Using assertions
  5. 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

QnoAnswer (Option with Text)
1B) A programming language for iOS and macOS development
2C) Apple
3A) .swift
4D) All of the above
5B) Objective-C
6B) iOS and macOS application development
7C) macOS
8B) Experimenting with Swift code interactively
9B) .storyboard
10B) Testing snippets of Swift code
11D) All of the above
12B) Classes and inheritance
13B) Stateless and predictable code behavior
14B) Variables cannot change after they are set
15A) Control flow statements like if, for, and while
16A) @main
17A) let
18A) var
19B) print("Hello, World!")
20A) //
21D) \()
22C) To exit a function early if conditions are not met
23C) func
24A) var x: Int?
25B) A runtime error occurs
26D) All of the above
27B) To handle exceptions or errors
28A) Executes code at the end of the scope
29B) Using the try-catch block
30A) To stop execution and provide a message

Use a Blank Sheet, Note your Answers and Finally tally with our answer at last. Give Yourself Score.

X
error: Content is protected !!
Scroll to Top