Note that there are some explanatory texts on larger screens.

plurals
  1. PONSManagedObject Incompatible pointer type warnings
    text
    copied!<p>Let me make sure first I have X-Code 4.3.2 version and iOS 5.1 SDK. I have below methods used in my project for core-data operation. Both method giving same warning. i.e <strong>"Incompatible pointer types returning 'NSManagedObject *' from a function with result type 'NSManagedObject &lt;Protocol> "</strong>.</p> <p><strong>Method A:</strong></p> <pre><code>- (NSManagedObject&lt;Protocol&gt; *)newMOforNilMOC { return [[NSManagedObject alloc] initWithEntity:[self entityDescription] insertIntoManagedObjectContext:nil]; } </code></pre> <p>For method <strong>method A</strong> I just do typecasting and added (NSManagedObject&lt;Protocol>*) then warning get removed as stated below. </p> <pre><code>- (NSManagedObject&lt;Protocol&gt; *)newMOforNilMOC { return (NSManagedObject&lt;Protocol&gt; *) [[NSManagedObject alloc] initWithEntity:[self entityDescription] insertIntoManagedObjectContext:nil]; } </code></pre> <p><strong>Method B:</strong></p> <pre><code>+ (NSManagedObject&lt;Protocol&gt; *) newInContext:(NSManagedObjectContext *)context { return [[NSEntityDescription insertNewObjectForEntityForName:[[(NSManagedObject&lt;Protocol&gt; *)self class] entityName] inManagedObjectContext:context]retain]; } </code></pre> <p>For <strong>method B</strong> when I do typecasting it will not work hence I just change the name of method from newInContext to AddnewInContext (Found somewhere when googled) then warning got removed.</p> <p>I have following Questions:</p> <ol> <li>If first method is required typecasting then why second one is not working with that solution?</li> <li>What is the exact meaning of changing the name of method. Is this proper way to remove above warning? Why typecasting not working in <strong>method B</strong>?</li> </ol> <p>This could be complicated one but feel free to leave comment if you have any doubt. Because I want to know the difference, at least I get to learn some new thing about core data.</p>
 

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