swift - what do parenthesis do after lazy var definition? -
i analyzing analyzing third party code , there "lazy" var statement looks this, , understand parenthesis doing after "computed property" curly braces:
lazy var defaults:nsuserdefaults = { return .standarduserdefaults() }()
the "return .standarduserdefaults()" returning nsuserdefaults instance object, why add () after right curly brace?
thanks
it means block executed first time defaults accessed. without () means defaults block type of variable of type () -> nsuserdefaults. when add () means it's nsuserdefaults returned block executed @ time of access.
Comments
Post a Comment