NSError class encapsulates information about an error into a single object. It consists of an error domain, a domain-specific error code, and a user information dictionary that contains specific information about the error. When we use
NSError in Swift we add an
NSError inout parameter of the
NSErrorPointer type to our method's parameter list.
As a general rule we should not use an
NSError instance to indicate whether an error occurred or not. Our methods should instead return either a
nil or a Boolean
false to indicate a failure. We can then use the
NSError instance to give details about the error that occurred.
Let's look at how we can use the
NSError class in our code. We will want to begin by defining our error ...