ios - XML Parsing goes to EXC_BAD_ACCESS code 1 address 0x10 -


so here thing. trying build no-arc/no-storyboard project without previous experience in manual memory-management. full source code available here. i've got here

class, helps me create products object custom initialiser

products.h

@interface products : nsobject  @property (nonatomic,retain)nsstring *productname; @property (nonatomic,retain)nsstring *productdescription; @property (nonatomic,retain)nsstring *productimage;  -(id) initwithname: (nsstring *) name        description: (nsstring *) description              image: (nsstring *) image;  @end 

products.m

@implementation products  -(id) initwithname:(nsstring *)name description:(nsstring *)description image:(nsstring *)image { self = [super init];  if (self) {     self.productname = name;     self.productdescription = description;     self.productimage = image; } return self;  @end 

there can see productparser class, 1 contains of magic

productsparser.h

@interface productsparser : nsobject <nsxmlparserdelegate>  @property (nonatomic,retain) nsmutablearray *productarray;  -(id) initwitharray:(nsmutablearray *) productarray; -(void) parsexmlfile;  @end 

productparser.m

    // creating private properties @interface productsparser() @property nsxmlparser *parser; @property nsstring *element;  @property nsmutablestring *currentproductname; @property nsmutablestring *currentproductdescription; @property nsmutablestring *currentproductimage;  @end    @implementation productsparser -(id) initwitharray:(nsmutablearray *)productarray {     self = [super init];     if (self) {         self.productarray = productarray;     }     return self; }  -(void) parsexmlfile {     // here instead of writing in viewdidload     nsurl *xmlpath = [[nsbundle mainbundle]urlforresource:@"productslist" withextension:@"xml" ];     self.parser = [[nsxmlparser alloc]initwithcontentsofurl:xmlpath];     self.parser.delegate = self;     [self.parser parse];     [self.parser release]; }  -(void) parser:(nsxmlparser *)parser didstartelement:(nsstring *)elementname namespaceuri:(nsstring *)namespaceuri qualifiedname:(nsstring *)qname attributes:(nsdictionary *)attributedict {     self.element = elementname; }  -(void) parser:(nsxmlparser *)parser foundcharacters:(nsstring *)string {     string = [string stringbyreplacingoccurrencesofstring:@"\n" withstring:@""];     string = [string stringbyreplacingoccurrencesofstring:@"\t" withstring:@""];     string = [string stringbyreplacingoccurrencesofstring:@"  " withstring:@""];      if ([self.element isequaltostring:@"name"]) {         if (self.currentproductname == nil) {             self.currentproductname = [[nsmutablestring alloc] initwithstring:string];         } else {             [self.currentproductname appendstring:string];         }     }     if ([self.element isequaltostring:@"description"]) {         if (self.currentproductdescription == nil) {             self.currentproductdescription = [[nsmutablestring alloc] initwithstring:string];         } else {             [self.currentproductdescription appendstring:string];         }     }    if ([self.element isequaltostring:@"image"]) {         if (self.currentproductimage == nil) {             self.currentproductimage = [[nsmutablestring alloc] initwithstring:string];         } else {             [self.currentproductimage appendstring:string];         }     } }  -(void) parser:(nsxmlparser *)parser didendelement:(nsstring *)elementname namespaceuri:(nsstring *)namespaceuri qualifiedname:(nsstring *)qname {     if ([elementname isequaltostring:@"product"]) {         products *thisproduct = [[products alloc] initwithname:self.currentproductname description:self.currentproductdescription image:self.currentproductimage];          [self.productarray addobject:thisproduct];           [self.currentproductname release];         self.currentproductname = nil;           [self.currentproductdescription release];         self.currentproductdescription = nil;           [self.currentproductimage release];         self.currentproductimage = nil;           [thisproduct release];         thisproduct = nil;           [self.element release];         self.element = nil;     } }  @end 

later on, in class suppose handle uitableview creating:

@property (retain,nonatomic)nsmutablearray *productarray; 

and in viewdidload have code

self.productarray = [[nsmutablearray alloc] init]; productsparser *menuparser = [[productsparser alloc] initwitharray:self.productarray]; [menuparser parsexmlfile]; [menuparser release]; 

all results in exc_bad_access pointing

@property (nonatomic,retain)nsstring *productname; 

i've done research error. users claims getting rid of error calling properties self. syntax.(which suppose increase retain count?) in case not issue, may see.(or did missed something?)

i can see in debugger productarray suppose populated products .xml file, in fact populated trash stuff @"/n/t" @"/n " @"/n/t" , on.(why why why?!)

so @ least point me, start. appreciate guys help.

update 1: apparently there defect logic, got rid of \n\t stuff changing code in foundcharacters section. instead of \n\t \n \n\t got actual data in array afterwards. so:

@"box of chocolate \n\t\t" @"box of chocolate, tasty \n" @"imagename \n\t" 

i know \n should new line, , \t apparently tabulation. still, don't have clear idea on how rid of , why popping up.

update 2: manage rid of trashy \n\t array adding stringbyreplacingoccurrencesofstring. (code updated)


Comments

Popular posts from this blog

c# - Better 64-bit byte array hash -

webrtc - Which ICE candidate am I using and why? -

php - Zend Framework / Skeleton-Application / Composer install issue -