I can’t see it working in tests.
Using accessors is ok:
A “regular one” is forbidden…
DerkJ and Christian are thinking exactly as I am.
I believe the programmer should be able to choose to implement either a property or computed property. I don’t believe the interface should enforce a computed property.
What the interface is saying is “make sure this class has a property called Name”. If the programmer wants to make it a regular property the compiler should be smart enough to figure that out. Many other programming languages support this.
Probably needs a read/write definition (empty computed)
But the implementations can have normal or computed if read and write
Show me an example please. As Swift is your current domain, what’s wrong with this:
protocol Greet {
// blueprint of property
var name: String;
// blueprint of a method
func message()
}
// conform class to Greet protocol
class Person: Greet {
// implementation of property
var name = "Peter"
// implementation of method
func message() {
print("Hello", name)
}
}
var spider = Person()
spider.message()
ERROR!
/tmp/65BkNnTOmJ.swift:4:7: error: property in protocol must have explicit { get } or { get set } specifier
var name: String;
^
{ get <#set#> }
// seems TO DEMAND being "computed", i.e. needs accessors.
The fix is:
protocol Greet {
// blueprint of property
var name: String {get} // computed
// blueprint of a method
func message()
}
@Rick_Araujo it’s all in the docs
https://docs.swift.org/swift-book/documentation/the-swift-programming-language/protocols/
Xojo is not swift and vice versa but the implementation explained there is the most flexible and probably the best fit.
Show me it working, please.