1

I am having trouble understanding why t and tt are treated differently. Obviously it has to due with what is specified directly in protocol A, but what is the logic here for this difference?

protocol A {
    var t : Int {get}
} 
extension A {
    var t : Int {
        return 1
    }
    var tt : Int {
        return 1
    }
}
struct B : A {
    var t = 2
    var tt = 2
}
let a:A = B()
print(a.t, a.tt) //"2 1"
let b:B = B()
print(b.t, b.tt) //"2 2"
gloo
  • 2,490
  • 3
  • 22
  • 38

0 Answers0