Join Scott Gardner for an in-depth discussion in this video Create error types, part of Swift 3 Essential Training: Beyond the Basics.
- [Instructor] I showed how to create…an error type enumeration in the basics course for use…with a throwing function.…Classes and structures can also be used…to create error types and recall…that error is actually an empty protocol.…By simply declaring an adoption of the error protocol,…instances of the type can be thrown as errors.…I'll define an http error type…with code and message properties.…And then I'll define a simulate http get throwing function.…
In it, first I'll get a random http status code…between 100 and 500.…Now I'll switch over that value.…For the first three possible values there are no errors…so I'll just print the result.…For 400 and 500 I'll throw an http error passing a code…and error message.…
And even though it seems…that the switch daemon should be able to infer…that I've covered every possible permutation…of http status code, it doesn't.…So I'll need to add a default.…Now I'll call simulate http error…and a do catch statement.…I need to cast the error object return as an http error…by using the as operator in order to access its properties.…
- Adding source files, resources, links, and literals
- Adding pages to a playground
- Using overflow operators and bitwise operators
- Using ranges with strings
- Creating complex sequences
- Chaining higher-order functions
- Defining lazy properties
- Using failable initializers
- Mutating methods
- Working with singletons
- Nesting function types
- Creating error types and recursive enumerations
- Extending concrete types
- Referencing selectors and key paths
- Working with protocol-oriented programming
- Defining class-only protocols and optional protocols
- Using option sets, type checking, and casting operators
Skill Level Intermediate
Core Data for iOS and macOS Enterprise Developerswith Jon Bott1h 46m Intermediate
Distributing Your iOS App for Testing with TestFlightwith Ron Buencamino35m 10s Intermediate
iOS App Development: Test-Driven Developmentwith Harrison Ferrone2h 14m Intermediate
3. Strings and Characters
4. Sequences and Collections
5. Control Flow
6. Value and Reference Types
9. Access Control
Understand access control3m 47s
Next steps1m 2s
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.