OA. free
Free
Sirionlabs, Inc Core Computer Science Core Computer Science Medium

Problem Statement: Given the following Swift code snippet, analyze the delegation pattern...

Sirionlabs, Inc technical mcq question, verified with a worked answer. Free to practise - no sign-up.

Problem Statement:**

Given the following Swift code snippet, analyze the delegation pattern and determine the output when toyshop.makeToy() is called.

class ToyShop {
    var delegate: ToyShopDelegate?
    
    func makeToy() {
        let toy = Toy()
        delegate?.toyWasMade(toy)
    }
}

class ToyManu: ToyShopDelegate {
    func toyWasMade(_ toy: Toy) {
        print(toy.height)
    }
}

let shop = ToyManu()
let toyshop = ToyShop()
toyshop.delegate = shop
toyshop.makeToy()

What is the output of this code?

Choose one option.
Show answer & explanation
Answer: A. A) 12

Accurate technical and quantitative evaluation based on foundational principles.

Step-by-step Derivation:
Step 1: Formulate problem conditions.
Step 2: Apply logical deduction.
Step 3: Conclude correct option.