iOS Development For Beginners 3 — Questions and Answers
Question 1: In Swift, which keyword declares a constant whose value cannot change?
- let (Correct answer)
- var
- const
- final
Correct answer: let
The 'let' keyword declares an immutable constant in Swift.
Question 2: Which keyword declares a variable that can be changed later in Swift?
- var (Correct answer)
- let
- mutable
- dynamic
Correct answer: var
The 'var' keyword declares a mutable variable in Swift.
Question 3: What is an Optional in Swift?
- A type that can hold either a value or nil (Correct answer)
- A required parameter
- A type of loop
- A UI component
Correct answer: A type that can hold either a value or nil
An Optional represents a value that may be present or absent (nil).
Question 4: Which symbol is used to mark a type as Optional in Swift?
- ? (Correct answer)
- !
- *
- &
Correct answer: ?
A trailing question mark (e.g., String?) marks a type as Optional.
Question 5: What does the 'func' keyword do in Swift?
- Declares a function (Correct answer)
- Declares a class
- Imports a framework
- Creates a loop
Correct answer: Declares a function
The 'func' keyword is used to define a function in Swift.
Question 6: In Swift, which collection type stores ordered values accessed by index?
- Array (Correct answer)
- Dictionary
- Set
- Tuple
Correct answer: Array
An Array stores an ordered collection of values accessed by index.
Question 7: Which Swift collection stores key-value pairs?
- Dictionary (Correct answer)
- Array
- Set
- Stack
Correct answer: Dictionary
A Dictionary stores unordered key-value pairs in Swift.
In Swift, which keyword declares a constant whose value cannot change?