Was researching on protocols with optional methods/properties, and a bit confused with compiler behavior.
In my understanding last line in provided code should not be reported as error, because BaseClass implements ProtocolWithOptionals, and so, can have "name" property.
Still I'm not sure if it is a bug, or just my wrong understanding.
Would be glad to hear thoughts from others before reporting as bug to Apple.
@objc protocol ProtocolWithOptionals: NSObjectProtocol {
@objc optional var name: String { get }
}
class BaseClass: NSObject, ProtocolWithOptionals { }
class ChildClass: BaseClass {
var name: String { return "ChildClass" }
}
let childClass: BaseClass = ChildClass()
print((childClass as ProtocolWithOptionals).name) // works fine
print(childClass.name) //ERROR: Value of type 'BaseClass' has no member 'name'