I want to write a class with 2 computed properties, where the second one references the first. I tried this:
class GraphView: UIView {
var graphVisibleSize: CGSize {
return CGSize(
width: self.bounds.size.width / 40,
height: self.bounds.size.height / 40)
}
var graphRect = CGRect {
return CGRect(
center: CGPointZero,
size: self.graphVisibleSize)
}
}
However, that results in an error. Xcode gives an error on the size: self.graphVisibleSize
line and says:
'GraphView -> () -> GraphView' does not have a member named 'graphVisibleSize'
What does this mean? Specifically:
What does the
GraphView -> () -> GraphView
part mean?Why can it not see the
graphVisibleSize
member that is right above it?Bonus question: I tried to replicate this in a test class and ended up writing a class that works just fine - but I don't understand what's different! Here's the one I wrote just as a test:
func mungeString(str: String) -> String { var newString = "--asdf--\(str)--qwer--" return newString } class TestClass: UIView { var baseA: String = "This is a string" var baseB: String { return "This is a computed string" } var changedA: String { return self.baseA.lowercaseString } var changedB: String { return mungeString(self.baseB) } }
Why does this code work just fine, but the original code give me an error?