Here's the code:
protocol A {
var a: Int { get set }
}
extension A {
var convenientAccessor: Int {
get { return a }
set { a = newValue }
}
}
class B: A {
var a: Int = 0
}
func acceptsB (instance: B) {
instance.a = 1 // This compiles
instance.convenientAccessor = 2 // This does not
}
I sort of understand the problem here, but I really would love both an answer from someone who understands it more deeply, and more importantly a workaround for my problem which is that I want to pass around known class types and be able to use convenient accessors without being inhibited by the non-possibility that I'm using a value type. In my case, the protocols which define these convenient accessors should not be class-bound (they are perfectly valid and useful for value types), so while that is technically a workaround, it is not satisfactory to me.