Introduction

Heads up... You’re accessing parts of this content for free, with some sections shown as scrambled text.

Heads up... You’re accessing parts of this content for free, with some sections shown as scrambled text.

Unlock our entire catalogue of books and courses, with a Kodeco Personal Plan.

Unlock now

The Result type is an enumeration with two cases — .success and .failure. Each case has an associated value — the result of a successful operation or an error. Using a Result type can make your code more readable and maintainable because it’s clear what constitutes success and failure. Your code is more robust because you must handle errors.

Although Result is often used in completion handlers for asynchronous functions, you can also use it for synchronous operations. Result can be especially useful when you want to store or pass the result of an operation. Task has a Result type property, and Result has an init(catching:) initializer that lets you capture the outcome of any throwing expression.

Learning Objectives

Here’s what you’ll learn in this lesson:

See forum comments
Download course materials from Github
Previous: Conclusion Next: Result Type