Do not quite understand the principle of computed properties?

I remember once I tried to learn objective-c I have left a certain belief that when we create a variable like : var per = 5 , then to create it work get and set methods.

But when I started to deal with computed properties, I realized that they do not store values and methods set and get are not working with direct variable where they are implemented.

And then I had a few questions:

Are there all those setters and the Thais who work with the most variable when it is created ?
Or are these setters and hetero - it's just an additional functionality, which is used to compute properties ?
And the variable we create without them, and usually?
June 3rd 19 at 19:17
1 answer
June 3rd 19 at 19:19
Solution
Each variable class has allocated memory and computed properties do not have. The getter and setter you just determine what that expression that is executed when the corresponding operation. A good example over time:
class Time {
 var seconds:Double = 0

 init(seconds: Double) {
 self.seconds = seconds
}

 var minutes: Double {
 get {
 return (seconds / 60)
}
 set {
 self.seconds = (newValue * 60)
}
}

 var hours: Double {
 get {
 return (seconds / (60 * 60))
}
 set {
 self.seconds = (newValue * (60 * 60))
}
}

 var days: Double {
 get {
 return (seconds / (60 * 60 * 24))
}
 set {
 self.seconds = (newValue * (60 * 60 * 24))
}
}
}


Just abstraction, you can of course use the function instead, but in some cases, more "elegant" or something..
Good example there is in the Swift iBook, the book with the rectangle.
Still want you to clarify

1.So you confirm that get and set does not participate in the creation of a normal variable ?

2. And set and get it's just "more convenient analogues of the function" in a calculated variable? - karli.Kub commented on June 3rd 19 at 19:22
well, as it is written in the documentation:
“In addition to stored properties, classes, structures, and enumerations can define computed properties, which do not actually store a value. Instead, they provide a getter and an optional setter to retrieve and set other properties and values indirectly.”

Excerpt From: Apple Inc. “The Swift Programming Language (Swift 3.0.1).” iBooks. https://itunes.apple.com/il/book/the-swift-program... - jamie85 commented on June 3rd 19 at 19:25
response to mark don't forget, if the decision to encourage the participants :) - jamie85 commented on June 3rd 19 at 19:28
thanks for the answer) - karli.Kub commented on June 3rd 19 at 19:31

Find more questions by tags Swift