O'Reilly logo

Swift Functional Programming - Second Edition by Dr. Fatih Nayebi

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

try?

We can use try? to handle an error by converting it to an optional value.

If an error is thrown while evaluating the try? expression, the value of the expression is going to be nil. For instance, in the following example, the result is going to be nil if we cannot read the file:

let result = try? readFile(path: "path/to") 

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required