It was a bad idea in ObjC, and it was illegal in Swift. Consider some of these cases:
class X { var value : Int = 0 func value() -> Int { return 1 } } let x = X()
What is x.value in this case? Is it Int or is it () -> Int ? It is legal and useful to treat class methods as closures.
What if we are even more complex and do this:
class X { let value: () -> Int = { 2 } func value() -> Int { return 1 } } let x = X() let v = x.value()
Should Swift use the value property and then call it? Or should it call the value() method? Closures are completely legal as properties.
The same restriction exists in ObjC. You could not create a synthesized property that would contradict the method (if they had different types, if they had the same time, ObjC would be silent to synthesize the accessor). You are thinking of Swift properties similar to ObjC ivars, but it is not. Swift properties are equivalent to ObjC properties (i.e. ivars access methods). You do not have access to the basic ivars in Swift.
source share