Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You mean the return value from that method?</p> <pre><code>+ (ContactInfo *)findOrCreateContact:(NSDictionary *)data inManagedObjectContext:(NSManagedObjectContext *)context </code></pre> <p>First the naming of the function state <code>find OR create</code> so with a name like that you should return an object in both case, the one you have find or the one just created. That would avoid possible confusion. </p> <p>Second, Your return type is an object, so you should return <code>nil</code> or an object. </p> <p>So at this point you have to decide if you want to comply with your naming or not, but let say you want.<br> You could have a method like this : </p> <pre><code>+ (ContactInfo *)findOrCreateContact:(NSDictionary *)data inManagedObjectContext:(NSManagedObjectContext *)context contactWasCreated:(BOOL *)isNew </code></pre> <p>By passing a pointer to a BOOL you can get set it to YES if the ContactInfo was created and NO if you are returning an one that already existed, and you can still return nil if you wasn't able to have a ContactInfo to return. Passing a BOOL as a pointer is inspired by <code>- (BOOL)save:(NSError **)error</code> where you are passing a pointer to an object an can retreive the NSError if needed.<br> So in your if you could say</p> <pre><code>if (contanctInfo &amp;&amp; wasCreated) { // I've got a new one } else if (contactInfo) { // I just receive an old one } else { // something very bad just happened... } </code></pre> <p>You could also decide to return a NSDictionary with the ContactInfo as one entry and a NSNumber for the BOOL as an other entry.</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. 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