Q: In Swift, what special type indicates a value might be absent?
Optional
Which Swift collection can hold multiple values of the same type in a specific order
Array
What is the term used to describe a function within another function?
Nested Function
In Swift, which one can have both stored and computed properties: Classes or Structures?
Both Classes and Structures
In Swift, what do you call a blueprint of methods, properties, and other requirements that can be adopted by a class, structure, or enumeration?
Protocol
Q: Which operator is used for string concatenation?
is +
Which loop in Swift checks the condition at the end?
repeat-while
Which term describes a self-contained block of functionality that can be passed around and used in your code?
Closure
Which keyword is used to represent the current instance within a method?
self
What Swift feature allows you to add new functionality to an existing type without modifying it?
Extension
How do you declare a multi-line string in Swift?
triple double quotes (""" ... """)
Which collection in Swift does not allow duplicate values and has no defined ordering?
Set
If a closure can outlive the function it was created in, what kind of closure is it
Escaping Closure
What is the process by which one class can acquire the properties and behaviors of another class, enabling code reusability in OOP?
Inheritance
What keyword is used before a protocol property to indicate that it can be both read and modified, but not set directly?
{ get set }
Which keyword is used to handle errors in a controlled manner?
throw or throws
What is the more compact way, introduced in Swift, to handle multiple optional bindings and provide a clear style?
guard statement
Which Swift feature allows functions to return multiple values
Tuple
In Swift, if you don't want a class to be subclassed further, which keyword would you use?
final
When defining a protocol, which keyword is used to specify that conforming types must also be a class?
AnyObject
What Swift feature enables you to group multiple related values, potentially of different types, without defining specific classes or structures?
Tuple
write a loop for a dictionary to iterate over the key and value
let dictionary: [String: Int] = ["apple": 5, "banana": 10, "cherry": 15]
for (key, value) in dictionary {
print("Key: \(key), Value: \(value)")
}
In functional programming in Swift, which higher-order function transforms an array of values into an array of different values based on some logic?
Map
Which design pattern involves a single central authority or instance controlling access to a resource or class?
Singleton Pattern
If a protocol method or property doesn't have to be implemented by a conforming type, what is it called?
Optional Requirement