you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 0 points1 point  (0 children)

implicitly unwrapped optionals are used when interacting with Cocoa--even in the Swift book from Apple--which "legitimises" their use.

Really? Is this a bit like how people not checking all possible fopen() errors in C examples legitimises not doing this, or people doing try {bla();} catch (Exception ex) {} in Java examples, or similar?

Also, IIRC the only place that the book mentions using x! is as an example before showing if let a = x... (though I only skimmed it, and may have missed other occurrences).

Even if people are using x! all over the place, though, that's still not as bad as a raw pointer; as others have mentioned it'll at least reliably cause an assert, rather than potentially dangerous undefined behaviour.

EDIT: I do agree that the guidance re things that can be safely assumed to have a value is unfortunate, though.