try
, try?
, and try!
in Swift?Suggested approach: A regular try
requires you to catch errors, try?
converts the throwing call into an optional where you’ll get back nil
on failure, and try!
will cause your app to crash if the throwing call fails. All three have their uses, so don’t dismiss one out of hand.
Estimated difficulty: Easy
See the full list of iOS interview questions
Link copied to your pasteboard.