1
votes

If an Implicitly unwrapped optionals as said in Swift Programming by Apple is supposed to always have a value then why not to use non-optionals instead ? I know know non-optionals can't be assigned to nil but is there any other difference?

2

2 Answers

2
votes

is there any other difference?

Impilicitly unwrapped optional can be compared with nil.

var a:String!
if a == nil {
    // a is nil
}
0
votes

The simplest answer is optional variables may not get values at all, In iOS development, this particular behavior is often required. So, instead of creating pointers(which is high cost) in objective-C, Swift has introduced the Optional variables. To know about the implicit and explicit optionals refer this link.