Square Yards Interview Question

Optional chaining

Interview Answer

Anonymous

Feb 12, 2018

I explained this programme to them:: class ElectionPoll { var candidate: Pollbooth? } lass Pollbooth { var name = "MP" } let cand = ElectionPoll() let candname = cand.candidate!.name The process of querying, calling properties, subscripts and methods on an optional that may be 'nil' is defined as optional chaining. Optional chaining return two values − if the optional contains a 'value' then calling its related property, methods and subscripts returns values if the optional contains a 'nil' value all its its related property, methods and subscripts returns nil