Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Essentially, the root of the issue is a hack for wanting to return a second (optional) object.</p> <p>How can we do this, as we can only return one thing? Well, we could return some sort of <code>(return_value, error)</code> tuple, but that's a bit unwieldy. We can have as many parameters as we like though, can we do something with those...</p> <p>So, methods/functions can't modify their parameters (to be precise, they operate with a copy, so any modifications they make are local). That is to say (concurrency issues aside) the value of <code>fetchRequest</code> before the message in your question will be equal to the value of <code>fetchRequest</code> afterwards. Note the object pointed to by <code>fetchRequest</code> might change, but the value of <code>fetchRequest</code> itself won't.</p> <p>This puts us in a bit of a bind. Except, wait, we know we can happily take the value of a parameter and modify what it points to! If you look at the declaration for <code>executeFetchRequest:error:</code> you'll see it takes an <code>NSError**</code>. That's "a pointer to a pointer to an <code>NSError</code>". So, we can initialise an empty/dangling <code>NSError*</code>, find the address of it (with the <a href="http://en.wikipedia.org/wiki/Operators_in_C_and_C++#Member_and_pointer_operators" rel="noreferrer">unary <code>&amp;</code> operator</a>), and pass that in. The method can then assign to the <code>NSError*</code> pointed to by this.</p> <p>Voila, we effectively have optional additional return values.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload