If I have a protocol that has an optional property, and a class that needs to conform to the protocol which has the same property already, but as a non-optional property, how do I make the class conform to the protocol.
protocol MyProtocol {
var a: String? { get set }
}
class MyClass {
var a: String
}
extension MyClass: MyProtocol {
// What do I put here to make the class conform
}
a,MyClasssatisfies a stronger postcondition than the protocol requires. Except ifais required writable thenMyClassfails, since it also strengthens the precondition - the protocol requires the optionality. But if the protocol statedaasgetonly, then is it true that a non-optional implementation ofacould indeed conform? (Tested it doesn't)