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)
}
                A static variable belongs to the class, not the instance. You can refer to the class by calling dynamicType:
print(a.dynamicType.x)
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With