I am creating a library that should return errors so I'm wondering which one should use for my purposes.
UPDATE: I should clarify, the returned result will be from a asynchronous call so I need to inform to the user if there was an error and I would like to know which type I should use Error or NSError.
NSError
is a Cocoa classError
is a Swift protocol which classes, structs and enums can andNSError
does conform to.The quoted parts are the subtitle descriptions in the documentation.
The Swift’s error handling system is the pattern to catch errors using
try - catch
. It requires that the error to be caught isthrown
by a method. This pattern is much more versatile than the traditional error handling usingNSError
instances. If you're planning not to implementtry - catch
you actually don't need theError
protocol.