Swift Basics
Control Flow & Collections
Functions & Closures
Object-Oriented Programming (OOP)
Protocols & Extensions
100

Q: In Swift, what special type indicates a value might be absent?

Optional

100

Which Swift collection can hold multiple values of the same type in a specific order

Array

100

What is the term used to describe a function within another function?

Nested Function

100

In Swift, which one can have both stored and computed properties: Classes or Structures?

Both Classes and Structures

100

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

200

Q: Which operator is used for string concatenation?

 is +

200

Which loop in Swift checks the condition at the end?

repeat-while

200

Which term describes a self-contained block of functionality that can be passed around and used in your code?

Closure

200

Which keyword is used to represent the current instance within a method?

self

200

What Swift feature allows you to add new functionality to an existing type without modifying it?

Extension

300

How do you declare a multi-line string in Swift?

triple double quotes (""" ... """)

300

Which collection in Swift does not allow duplicate values and has no defined ordering?

Set

300

If a closure can outlive the function it was created in, what kind of closure is it

Escaping Closure

300

What is the process by which one class can acquire the properties and behaviors of another class, enabling code reusability in OOP?

Inheritance

300

What keyword is used before a protocol property to indicate that it can be both read and modified, but not set directly?

{ get set }

400

Which keyword is used to handle errors in a controlled manner?

throw or throws

400

What is the more compact way, introduced in Swift, to handle multiple optional bindings and provide a clear style?

guard statement

400

Which Swift feature allows functions to return multiple values

Tuple

400

In Swift, if you don't want a class to be subclassed further, which keyword would you use?

final

400

When defining a protocol, which keyword is used to specify that conforming types must also be a class?

AnyObject

500

What Swift feature enables you to group multiple related values, potentially of different types, without defining specific classes or structures?

Tuple

500

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)")

}


500

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

500

Which design pattern involves a single central authority or instance controlling access to a resource or class?

Singleton Pattern

500

If a protocol method or property doesn't have to be implemented by a conforming type, what is it called?

Optional Requirement