Skip to content

Final graded quiz: Advanced Programming in Swift :Advanced Programming in Swift (Meta iOS Developer Professional Certificate) Answers 2026

Question 1

Which of the following keywords helps create a value type?

❌ Class
❌ class
struct
enum

Explanation:
Swift me value types struct aur enum hote hain. class reference type hota hai.


Question 2

Which of the following code will compile?

class Wallet {
let dollars: Double?
}

class Wallet {
var dollars: Double =10
}

class Wallet {
let dollars: Double? = nil
}

class Wallet {
let dollars: Double
init(_ dollars: Double) {
dollars = dollars
}
}

Explanation:

  • Double = "10" ❌ type mismatch

  • initializer me self.dollars = dollars nahi likha ❌

  • Optional ko nil assign karna valid hai ✅


Question 3

Which of the following options is a valid console output?

["coffee", "coffee", "smoothie", "smoothie", "smoothie", "blueberries"]
["blueberries", "smoothie", "coffee"]
❌ None

Explanation:
Set duplicate values remove karta hai aur order guarantee nahi karta.


Question 4

Which of the following code options will compile successfully?

❌ Option 1

let book = Book()
book.updateBookTitle("Secret Ingredients")

Option 2

var book = Book()
book.updateBookTitle("Secret Ingredients")

❌ Option 3

func updateBookTitle(_ title: String) {
self.title = title
}

Explanation:

  • mutating function ko call karne ke liye struct instance var hona chahiye

  • non-mutating function me self.title change nahi kar sakte


Question 5

Which of the following access-level modifiers is suitable for subclassing a custom data type between modules?

❌ public
❌ private
open
❌ fileprivate
❌ internal

Explanation:
open hi ek aisa access level hai jo module ke bahar subclassing allow karta hai.


Question 6

Which of the following code blocks is a valid protocol declaration?

protocol Book {
var title: String
func share()
}

protocol Book {
var title: String
func share() { get }
}

protocol Book {
var title: String { get }
func share()
}

Explanation:
Protocol properties ko { get } ya { get set } specify karna zaroori hota hai.


Question 7

What will the console output?

❌ Deliver food by car
❌ No delegate found.
Nothing

Explanation:
delegate set hi nahi kiya gaya, aur deliverFood() call bhi nahi hua → koi output nahi.


Question 8

What will the console output?

healthy strawberry
healthy blueberry

Berries:
strawberry
blueberry
grape
goji

Berries:
healthy strawberry
healthy blueberry
healthy grape
healthy goji

Berries:
healthy strawberry
healthy blueberry

Explanation:

  • filter { $0.count > 5 } → strawberry, blueberry

  • map → “healthy ___”

  • reduce → prefix "Berries:\n"


Question 9

How many times will the console output Berry?

❌ 0
❌ 1
3

Explanation:
Berry, Blueberry, Strawberrysab Berry ke instance hain, isliye loop me 3 baar print hoga.


Question 10

Which of the following test methods will pass? (Select all that apply)

XCTAssertEqual(blueberry.color, "blue")

XCTAssert(!blueberry.color.isEmpty)

func test_blueberryColor_initialize_equalsBlue() {
}

XCTAssert(blueberry.color == "blue")

Explanation:

  • Empty test ❌ fail hota hai

  • Baaki teen assertions logically true hain ✅


🧾 Summary Table

Question Correct Answer
Q1 struct, enum
Q2 Optional initialized to nil
Q3 Set with unique values
Q4 var book with mutating
Q5 open
Q6 Property with { get }
Q7 Nothing
Q8 Berries + healthy strawberry & blueberry
Q9 3
Q10 1st, 2nd, 4th