FileWatcher icon indicating copy to clipboard operation
FileWatcher copied to clipboard

Optional variables as lazy?

Open eonist opened this issue 8 years ago • 0 comments

Could we make the instance variable non-optional? Example:

lazy var someSize:CGSize = {
   let x:CGFloat = 0
   let y:CGFloat = 0
   let size = CGSize(x,y,0,0)
   return size
}()

//Now we can use someSize with out force unwrap 👌
//What happens is that the var isn't created until something asks for it.
print(someSize.x)

eonist avatar May 09 '17 22:05 eonist