swift - Why create "Implicitly Unwrapped Optionals"? -
why create "implicitly unwrapped optional" vs creating regular variable or constant. if know can unwrapped why create optional in first place? example, why this:
let somestring : string! = "this string"
going more useful vs:
let somestring : string = "this string"
if “optional indicate constant or variable allowed have 'no value'”
, “sometimes clear program’s structure optional have value after value first set”
, point of making optional in first place? if know optional going have value... doesn't make it.... not optional?
consider case of object may have nil properties while it's being constructed , configured, immutable , non-nil afterwards (nsimage treated way, though in case it's still useful mutate sometimes). implicitly unwrapped optionals clean code deal, relatively low loss of safety (as long 1 guarantee held, safe).
(edit) clear though: regular optionals preferable.
Comments
Post a Comment