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

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -