Skip to content

Optional variables as lazy?#2

Description

@eonist

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)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions