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 6955035
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T14:41:04+00:00 2026-05-27T14:41:04+00:00

I’m building(trying … ) an iPhone application. My first user story is a login

  • 0

I’m building(trying … ) an iPhone application.
My first user story is a login View who send the credential of the user to a webservice (WCF).
The communication process with the web service is working fine without any problem.
But I have to deserialize the message coming form it. For that I used the NSXMLParser to create the message Object who contain the response of the service. This when the problem begin :

This is the Message parser :

.h

@interface MessageParser : NSObject  <NSXMLParserDelegate> {
    NSMutableString* currentProperty;
    Message* message;
}

@property (nonatomic, retain) NSMutableString* currentProperty;
@property (nonatomic, retain) Message* message;

- (void)parseMessageData:(NSData *)data parseError:(NSError **)err;

@end

.m

@implementation MessageParser

@synthesize message, currentProperty;

- (void)parseMessageData:(NSData *)data parseError:(NSError **)err 
{
    NSXMLParser *parser = [[NSXMLParser alloc] initWithData:data];

    [parser setDelegate:self]; 
    [parser setShouldProcessNamespaces:NO]; 
    [parser setShouldReportNamespacePrefixes:NO]; 
    [parser setShouldResolveExternalEntities:NO]; 

    [parser parse];

    if (err && [parser parserError]) {
        *err = [parser parserError];
    }

    [parser release];
}

-(void) parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict
{
    if(qName){
        elementName = qName;
    }

    if([elementName isEqualToString:@"Message"]){
        self.message = [[Message alloc] init];
    }
    else if( [elementName isEqualToString:@"body"] || [elementName isEqualToString:@"code"] || [elementName isEqualToString:@"error"]){
        currentProperty = [NSMutableString string];
    }
}

-(void) parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName
{
    if(qName){
        elementName = qName;
    }
    if(message){
        if([elementName isEqualToString:@"body"]){
            self.message.messageBody = currentProperty;
        }
        else if([elementName isEqualToString:@"error"]){
            self.message.error = currentProperty;
        }
        else if([elementName isEqualToString:@"code"]){

            NSNumberFormatter * f = [[NSNumberFormatter alloc] init];            
            [f setNumberStyle:NSNumberFormatterDecimalStyle];

            self.message.messageCode = [f numberFromString:currentProperty];
            [f release];
        }
    }

    self.currentProperty = nil;
}

- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)foundedCharacters
{
    if (self.currentProperty) {
        [currentProperty appendFormat:@"%@", foundedCharacters];
    }
}

this is the Login action :

- (IBAction)didLogin:(id)sender 
{
    NSData* receivedData;
    NSError* parserError;
    NSError* error;

    receivedData = [[ServiceClient PerformLogin:txtLogin.text withPassword:txtPassword.text error:error] retain];    
    MessageParser* messageParser = [[MessageParser alloc] init];

    Message* msg;    
    [messageParser parseMessageData:receivedData parseError:&parserError];

    msg = [messageParser.message retain];

    if(msg && !msg.error){        

        UIAlertView* alert = [[UIAlertView alloc] initWithTitle:@"Login Service Response" message:msg.messageBody delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil];
        [alert show];
        [alert release];
    }
    else if(msg.error){
        UIAlertView* alert = [[UIAlertView alloc] initWithTitle:@"Error" message:msg.error delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil];
        [alert show];
        [alert release];
    }
    else if(!msg){
        UIAlertView* alert = [[UIAlertView alloc] initWithTitle:@"Error" message:@"Enable to contact the Athentication service." delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil];
        [alert show];
        [alert release];
    }
}

the Message Object :

@interface Message : NSObject{
    NSString* messageBody;
    NSNumber* messageCode;
    NSString* error;   
}

@property (retain, nonatomic) NSString* messageBody;
@property (retain, nonatomic) NSNumber* messageCode;
@property (retain, nonatomic) NSString* error;

@end

@implementation Message
@synthesize error, messageBody, messageCode;

@end

So what is happened ?
Some time when is clik login it show me the alert then xcode throw me EXC_BAD_ACCESS error in the main.m in this code :

@autoreleasepool {
    return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
}

And some time when I click login it throw me the same error directly.

What’s wrong with my code ? Do I have some memory management problems ? where ?

Thank you.

  • 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-27T14:41:05+00:00Added an answer on May 27, 2026 at 2:41 pm

    You are using a convenience method without retaining the result….

    currentProperty = [NSMutableString string];
    

    either do…

    currentProperty = [[NSMutableString string] retain];
    

    or seeing as you declare the property with a retain attribute use…

    self.currentProperty = [NSMutableString string];
    

    Also note that the following line is leaking memory….

    self.message = [[Message alloc] init];
    

    as the property also has a retain attribute you need to release the version you create…

    Message *aMessage = [[Message alloc] init];
    self.message = aMessage;
    [aMessage release];
    

    …or…

    message = [[Message alloc] init];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We're building an app, our first using Rails 3, and we're having to build
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I need to clean up various Word 'smart' characters in user input, including but
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I have an MVC Razor view @{ ViewBag.Title = Index; var c = (char)146;
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka

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.