Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7031125
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T00:45:42+00:00 2026-05-28T00:45:42+00:00

This is my first time trying to accomplish core data and been having some

  • 0

This is my first time trying to accomplish core data and been having some issues getting things working. I have a xml parser in my app that I have been trying to add all the info into core data from but keep crashing on start. I have my core data set up with 1 Entity as “Themes”. In that entity I have 15 attributes. Below is the automatic file xcode can created for a ManagedObject after I created my .CoreData.

    Themes.h

    #import <Foundation/Foundation.h>
    #import <CoreData/CoreData.h>


    @interface Themes : NSManagedObject

    @property (nonatomic, retain) NSString * themeName;
    @property (nonatomic, retain) NSString * themeArtist;
    @property (nonatomic, retain) NSString * themeImage;
    @property (nonatomic, retain) NSString * themeDescription;
    @property (nonatomic, retain) NSString * twitterName;
    @property (nonatomic, retain) NSString * themePrice;
    @property (nonatomic, retain) NSString * screenshots;
    @property (nonatomic, retain) NSString * cydiaLink;
    @property (nonatomic, retain) NSString * themeVersion;
    @property (nonatomic, retain) NSString * deciption;
    @property (nonatomic, retain) NSString * repo;
    @property (nonatomic, retain) NSString * hd;
    @property (nonatomic, retain) NSString * sd;
    @property (nonatomic, retain) NSString * ipad;

    @end



#import "Themes.h"


@implementation Themes

@dynamic themeName;
@dynamic themeArtist;
@dynamic themeImage;
@dynamic themeDescription;
@dynamic twitterName;
@dynamic themePrice;
@dynamic screenshots;
@dynamic cydiaLink;
@dynamic themeVersion;
@dynamic deciption;
@dynamic repo;
@dynamic hd;
@dynamic sd;
@dynamic ipad;

-(void)setThemeName:(NSString *)themeName{

self.themeName = [themeName copy];


}



@end

Here is my xml Parser files where all the magic is supposed to happen. Overall everything works great with my parser it is just when I do

“themesObjects = (Themes *)[NSEntityDescription
insertNewObjectForEntityForName:themesObjects.themeName”
inManagedObjectContext:managedObjectContext];”

the app will crash I assume because I am not correctly inserting the object into the coredata.

#import <Foundation/Foundation.h>
#import "ThemeParseObject.h"
#import "Themes.h"


@class ThemeParseObject;

@interface ThemeXMLParser : NSObject <NSXMLParserDelegate>  {

 NSMutableData *recivedData;
 NSMutableArray *themes;
 NSMutableString    *currentNodeContent;
 NSXMLParser        *parser;

Themes *themesObjects;
NSManagedObjectContext *managedObjectContext;  
NSMutableArray *themeArray;   

ThemeParseObject *currentTheme;

}
@property (readonly, retain) NSMutableArray *themes;
@property (nonatomic, retain) NSManagedObjectContext *managedObjectContext;  
@property (nonatomic, retain) NSMutableArray *themeArray;   


-(id) loadXMLByURL:(NSString *)urlString;

@end


#import "ThemeXMLParser.h"


@implementation ThemeXMLParser

@synthesize themes;
@synthesize managedObjectContext;
@synthesize themeArray;



-(id) loadXMLByURL:(NSString *)urlString{


themesObjects = [[Themes alloc]init];
managedObjectContext = [[NSManagedObjectContext alloc] init];
themes          = [[NSMutableArray alloc] init];
NSURL *url      = [NSURL URLWithString:urlString];
NSData  *data   = [[NSData alloc] initWithContentsOfURL:url];
parser          = [[NSXMLParser alloc] initWithData:data];
parser.delegate = self;
[parser parse];
return self;    

}

- (void) parser:(NSXMLParser *)parser didStartElement:(NSString *)elementname   
namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName 
attributes:(NSDictionary *)attributeDict
{


if ([elementname isEqualToString:@"theme"]) 
{
    currentTheme = [ThemeParseObject alloc];
}
}


- (void) parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName     
namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName
{  



NSManagedObjectContext *context = [self managedObjectContext];
NSManagedObject *ObjectsToInsert = [NSEntityDescription
                                 insertNewObjectForEntityForName:@"Themes" 
                                 inManagedObjectContext:context];    

if ([elementName isEqualToString:@"name"]) {

    currentTheme.themeNameString = currentNodeContent;

    themesObjects.themeName = currentTheme.themeNameString;

    [ObjectsToInsert setValue:themesObjects.themeName forKey:@"themeName"];


}
if ([elementName isEqualToString:@"creator"]) {

    currentTheme.themeCreator = currentNodeContent;
   // themesObjects = (Themes *)[NSEntityDescription 
insertNewObjectForEntityForName:@"themeArtist" 
inManagedObjectContext:managedObjectContext];  


}    
if ([elementName isEqualToString:@"price"]) {

    currentTheme.themePrice = currentNodeContent;
    //themesObjects = (Themes *)[NSEntityDescription 
insertNewObjectForEntityForName:@"themePrice" 
inManagedObjectContext:managedObjectContext];  


}      
if ([elementName isEqualToString:@"twitter"]) {

    currentTheme.creatorTwitterName = currentNodeContent;
    //themesObjects = (Themes *)[NSEntityDescription 
insertNewObjectForEntityForName:@"twitterName"   
inManagedObjectContext:managedObjectContext];  


}  
if ([elementName isEqualToString:@"link"]) {

    currentTheme.cydiaLink = currentNodeContent;
    //themesObjects = (Themes *)[NSEntityDescription 
insertNewObjectForEntityForName:@"cydiaLink" 
inManagedObjectContext:managedObjectContext];  

}   
if ([elementName isEqualToString:@"deciption"]) {

    currentTheme.deciption = currentNodeContent;
    //themesObjects = (Themes *)[NSEntityDescription 
insertNewObjectForEntityForName:@"deciption"   
inManagedObjectContext:managedObjectContext];  

}     

if ([elementName isEqualToString:@"screenshots"]) {

    currentTheme.screenShots = currentNodeContent;

}        
if ([elementName isEqualToString:@"promo"]) {

    currentTheme.tblViewImage = currentNodeContent;
} 

if ([elementName isEqualToString:@"description"]) {

    currentTheme.themeDescription = currentNodeContent;

}     

if ([elementName isEqualToString:@"version"]) {

    currentTheme.themeVersion = currentNodeContent;

  //   NSLog(@"version: %@", currentNodeContent);        
}       

if ([elementName isEqualToString:@"repo"]) {

    currentTheme.themeRepo = currentNodeContent;

   // NSLog(@"repo: %@", currentNodeContent);

}       

if ([elementName isEqualToString:@"HD"]) {

    currentTheme.HD = currentNodeContent;

  //  NSLog(@"HD: %@", currentNodeContent);

}     

if ([elementName isEqualToString:@"SD"]) {

    currentTheme.SD = currentNodeContent;

   // NSLog(@"SD: %@", currentNodeContent);

}   

if ([elementName isEqualToString:@"iPad"]) {

    currentTheme.ipad = currentNodeContent;

    //NSLog(@"iPad: %@", currentNodeContent);

}       

if ([elementName isEqualToString:@"iPhoneScreenshots"]) {

    currentTheme.fullScreenShots = currentNodeContent;
   // themesObjects = (Themes *)[NSEntityDescription   
insertNewObjectForEntityForName:@"screenshots"   
inManagedObjectContext:managedObjectContext];         
  //  NSLog(@"fullScreenShots: %@", currentNodeContent);

    }     

    if ([elementName isEqualToString:@"theme"]) 
{

    [themes addObject:currentTheme];
    [currentTheme release];
    currentTheme = nil;
    [currentNodeContent release];
    currentNodeContent = nil;

}


}

- (void) parser:(NSXMLParser *)parser foundCharacters:(NSString *)string
{
currentNodeContent = (NSMutableString *) [string    
stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
}

This is what gets logged when the app crashes

2012-01-06 08:02:18.619 ThemeCatcher[2667:207] CoreData: error: Failed to call   
designated initializer on NSManagedObject class 'Themes' 
2012-01-06 08:02:19.000 ThemeCatcher[2667:207] -[Themes themeName]: unrecognized   
selector sent to instance 0x87072d0

If anyone has any suggestion or ideas where I can go from here that would be awesome. I apologize if this seems like a lot of code to look at but I felt it was nessicarry to give others an idea what really is going on inside the code… Thank you I appreciate any help given immensely!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T00:45:43+00:00Added an answer on May 28, 2026 at 12:45 am
    themesObjects = [[Themes alloc]init];
    managedObjectContext = [[NSManagedObjectContext alloc] init];
    

    I see two things wrong in these two lines. First, you’re not using the designated initializer for NSManagedObject in your Themes initializer. I know that for two reasons: a) that’s exactly what the error message says; b) the initializer can’t know what context to use because you haven’t created the context at that point. The designated initializer for NSManagedObjectContext is:

    -initWithEntity:insertIntoManagedObjectContext:
    

    However, it’s common practice to use NSEntityDescription’s + insertNewObjectForEntityForName:inManagedObjectContext: convenience method to create and add new objects to a context instead. Either way, you need to use one of these.

    The second problem is that you don’t have a managed object context when you create your Themes object, and it looks like you’re not setting up the context correctly when you do create it. You should be setting a persistent store coordinator for the context after you create it.

    Update: A third problem is that when you write:

    themesObjects = (Themes *)[NSEntityDescription insertNewObjectForEntityForName:themesObjects.themeName" inManagedObjectContext:managedObjectContext];
    

    you need to make sure that the model has an entity that matches the value of themeObjects.themeName. It’d be unusual to use data that you get from an XML file to determine the theme name, because a mistake in the XML file would cause an error, and also because it strongly ties the structure of the XML to your Core Data model. Be sure that you’re not confusing the concept of XML entity with Core Data entity — those are two different things. Core Data entities are the different types of objects in your model; you probably have an entity for Themes, for example.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have just installed a custom WordPress theme (this is my first time working
this is my first time trying to use document classes in AS3 and im
This is the first time I'm trying random numbers with C (I miss C#).
This is my first time making a hash table. I'm trying to associate strings
Disclaimer: This is my first time writing unit tests...be gentle! :) I am trying
This is my first time with Web services. I have to develop web services
this is my first time posting here, I have a question which I have
This is my first time trying to use Web Start, and I am trying
I'm first time poster here trying to pick up some Python skills; please be
This is what I'm trying to accomplish: I want to have a canvas that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.