Static variables in protocols

Viewed 5681

I have a protocol A which has a static variabe x. B is a implementation of A. In Class C I pass an instance of B and assigned it to a. How can I access 2 (value of x in class B) from it ?

protocol A {
 static var x : Int { get }  
}

class B : A {
 static var x: Int {
  return 2 
}
}


class C {
// instance of B is assigned to a. 
let a: A


print(a.x)
}
3 Answers

So things have changed a little bit since this answer was posted

type(of: a).x
Related