struct Person
{
var personName:String?
init(name:String) {
personName=name
}
lazy var greetLazy:String =
{
return "Hello \(self.personName!)"
}()
func greetFunc()->String
{
return "Hello \(self.personName!)"
}
}
var person:Person=Person(name:"")
print(person.greetLazy)
print(person.greetFunc())
I created 2 things viz a lazy property and a function to do the same thing. Now its said that the value of greetLazy will only be calculated when its first accessed,so when I access it using person.greetLazy it prints to the consoleand thats what lazy is supposed to mean.
My Question here is in case of function also the value will be returned only if i access the function. It wont precalculate it. So what would be the difference between the two in that case?