0

I am writing a method that performs an action which will give us an array of NSErrors. After this, we must handle the returned array:

  1. If the array is empty, no error has occurred and we continue as normal
  2. If the array has one item, that is the culprit so we alert the user, pass it in an NSError (with code: culprit.code) to a device control API that only takes one error, and prematurely return.
  3. If the array has multiple items, we alert the user of all these errors, pass a generic NSError (with code: 0) to the API, and return.

I want to improve case 3 so that the code (an NSInteger) is representative of multiple errors having occurred. Is there a standard way to represent this in Objective C, similar to how NSNotFound represents that none was found?

Ky -
  • 30,724
  • 51
  • 192
  • 308
  • 2
    The closest thing that comes to mind is based on the fact that a `NSError` can have a user dictionary attached. One of the standard keys is `NSUnderlyingErrorKey`, which is sometimes used to describe a cascade of errors. – Phillip Mills May 04 '15 at 19:33
  • @PhillipMills Vaguely brilliant. :) You should give that as an answer. – matt May 04 '15 at 19:34
  • @PhillipMills sounds promising! Can you elaborate on that in an answer? – Ky - May 04 '15 at 19:53

0 Answers0