Note that there are some explanatory texts on larger screens.

plurals
  1. POInit NSManagedObject subclass
    text
    copied!<p>I would like to know if it's possible to init a subclass of NSManagedObject ? I have a class "Actualite" which is a subclass of NSManagedObject and when I want to initialize this class, I get this error : "CoreData: error: Failed to call designated initializer on NSManagedObject class Actualite", and the app crashes after this message "-[Actualite setTitre:]: unrecognized selector sent to instance 0x8433be0"</p> <p>Here is my code :</p> <pre><code>-(void) recupererActualites { listeNouvellesActualites = [[NSMutableArray alloc] init]; // Convert the supplied URL string into a usable URL object NSURL *url = [NSURL URLWithString:FACE06_RSS]; // Create a new rssParser object based on the TouchXML "CXMLDocument" class, this is the // object that actually grabs and processes the RSS data CXMLDocument *rssParser = [[CXMLDocument alloc] initWithContentsOfURL:url encoding:NSUTF8StringEncoding options:0 error:nil]; // Create a new Array object to be used with the looping of the results from the rssParser NSArray *resultNodes = NULL; // Set the resultNodes Array to contain an object for every instance of an node in our RSS feed resultNodes = [rssParser nodesForXPath:@"//item" error:nil]; NSMutableArray* tmp = [[NSMutableArray alloc] init]; for (CXMLElement* resultElement in resultNodes) { // Create a temporary MutableDictionary to store the items fields in, which will eventually end up in blogEntries NSMutableDictionary *blogItem = [[NSMutableDictionary alloc] init]; NSMutableArray* categories = [[NSMutableArray alloc] init]; // Create a counter variable as type "int" int counter; // Loop through the children of the current node for(counter = 0; counter &lt; [resultElement childCount]; counter++) { // Add each field to the blogItem Dictionary with the node name as key and node value as the value if([[[resultElement childAtIndex:counter] name] isEqual:@"category"]) [categories addObject:[[resultElement childAtIndex:counter] stringValue]]; else { if ([[resultElement childAtIndex:counter] stringValue] != nil) [blogItem setObject:[[resultElement childAtIndex:counter] stringValue] forKey:[[resultElement childAtIndex:counter] name]]; else [blogItem setObject:@"" forKey:[[resultElement childAtIndex:counter] name]]; } } Actualite* actu = [[Actualite alloc] init]; [blogItem setObject:categories forKey:@"categories"]; [actu initWithDictionnary:blogItem]; [tmp addObject:actu]; //[actu release]; [categories release]; [blogItem release]; } listeNouvellesActualites = tmp; [rssParser release]; resultNodes = nil; // Stockage des actualités en local [self stockerActualites]; } </code></pre> <p>And the initWithDictionary method set all the attributes of the Actualite class.</p> <p>I also tried </p> <pre><code>Actualite* actu = [[Actualite alloc] initWithEntity:[NSEntityDescription entityForName:@"Actualite" inManagedObjectContext:managedObjectContext] insertIntoManagedObjectContext:managedObjectContext]; </code></pre> <p>and</p> <pre><code>Actualite* actu = (Actualite*)[NSEntityDescription entityForName:@"Actualite" inManagedObjectContext:managedObjectContext]; </code></pre> <p>instead of </p> <pre><code>Actualite* actu = [[Actualite alloc] init]; </code></pre> <p>The errors disappear but the app stops at this point. I don't know what can I do...</p> <p>Is someone already had this problem ?</p> <p>Thanks a lot !</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