Sobes.tech
Junior — Senior

What is the output in example №40

livecode

Task condition

In this Swift example, a protocol without requirements is declared, to which an extension with a computed property value is added. A class implementing the protocol also declares its own value property. Then, an instance of the class is created, along with a variable of the protocol type referencing the same object. It is necessary to understand what strings will be printed by print when accessing the property through the class variable and through the protocol variable.

protocol TheProtocol {
    
}

extension TheProtocol {
    var value: String {
        return "in TheProtocol"
    }
}

class TheClass: TheProtocol {
    var value: String {
        return "in TheClass"
    }
}

let myClass = TheClass()
let myProtocol: TheProtocol = myClass

print(myClass.value)      // ?
print(myProtocol.value)   // ?