Skip to content

Module quiz: Error handling, functional programming and testing :Advanced Programming in Swift (Meta iOS Developer Professional Certificate) Answers 2026


Question 1

Which of the following expressions is used to mark function as throwable?

❌ try throwable()
throws
❌ throw

Explanation: Swift me function ko throwable declare karne ke liye function signature me throws keyword use hota hai.


Question 2

Will the following code run without issues?

do {
print("hello")
}
catch {
print("Error caught")
}
catch {
print("Another error caught")
}

❌ No, there cannot be two catch blocks after each other.
❌ Yes, but first catch block will be executed.
Yes, code runs with no issues

Explanation: Swift me ek do ke baad multiple catch blocks allowed hote hain, jab tak syntax sahi ho.


Question 3

Which of the following expressions will convert thrown error into nil value?

❌ try!
❌ try
try?

Explanation: try? error ko handle karke nil return karta hai agar error throw hota hai.


Question 4

Can the following class be thrown as an error?

class MyClass: NSError {
}

Yes
❌ No, as it does not extend Error protocol.
❌ No, as classes cannot be thrown as errors.

Explanation: NSError already Error protocol ko conform karta hai, isliye ye throw ho sakta hai.


Question 5

What statement is used to execute code when leaving the current scope?

❌ do
defer
❌ catch

Explanation: defer block tab execute hota hai jab current scope se bahar nikalte hain.


Question 6

What is a multi-recursion?

❌ When a function has a call to itself in the beginning of its implementation.
It’s when function has multiple call to itself in its implementation.
❌ When a function has a call to itself in the end of its implementation.

Explanation: Jab ek function apne aap ko ek se zyada jagah call kare, use multi-recursion kehte hain.


Question 7

Functional programming is when a function can throw an error?

True
False

Explanation: Functional programming ka matlab immutability, pure functions, aur higher-order functions hota hai — error throwing se direct relation nahi.


Question 8

Which of the following functions are higher order functions? (Select all that apply)

map
❌ defer
filter

Explanation: Higher-order functions wo hoti hain jo function ko input ya output ke roop me leti/deti hain — map aur filter dono aisi hi hain.


Question 9

Which library in Xcode allows you to implement unit tests?

❌ XCTestCase
❌ XCTAssert
XCTest

Explanation: XCTest framework unit testing ke liye use hota hai; baaki classes/functions usi ka part hain.


Question 10

Mock can be used instead of a fake.

True
❌ False

Explanation: Testing me mock aur fake dono test doubles hote hain; kai cases me mock fake ka replacement ho sakta hai.


🧾 Summary Table

Question Correct Answer
Q1 throws
Q2 Yes, code runs with no issues
Q3 try?
Q4 Yes
Q5 defer
Q6 Multiple self-calls
Q7 False
Q8 map, filter
Q9 XCTest
Q10 True