When I call the following, the compiler complains that I am missing argument for parameter #1 in call :
import Foundation
class Person {
func uniqueID() -> String {
return NSUUID().UUIDString
}
lazy var sessionID: String = uniqueID()
}
let p = Person()
p.sessionID
p.sessionID
p.sessionID
When I replace the line with:
lazy var sessionID: String = NSUUID().UUIDString
It works.
What is causing the problem calling the function in a lazy initialization?
Interestingly, calling a closure works, even if the syntax looks clunky and heavy, as I would have to guard it if self is a weak reference:
lazy var sessionID: String = {
return self.uniqueID()
}()