iphone - Crash Error Help NSString -


i have code looks this:

nsstring *_parse = [nsstring stringwithformat:@"//%@",_user]; nsstring *_status = [parser parse:_parse:@"status"]; //parses xml if ([_status isequaltostring:@"1"]) { //error here } 

the application crashes when checks if strings equal. however, works fine when replace first line of code this:

    nsstring *_parse = [nsstring stringwithformat:@"//user1"]; 

but not use "user" ivar need used because value can different. ivar "user" nsstring declared earlier [self setuser:@"userx"]; should fix this? thanks

edit: here code parses xml:

+ (nsstring *)datafilepath:(bool)forsave {  nsarray *paths = nssearchpathfordirectoriesindomains(nsdocumentdirectory, nsuserdomainmask, yes);         nsstring *documentsdirectory = [paths objectatindex:0];         nsstring *documentspath = [documentsdirectory stringbyappendingpathcomponent:@"hangout.xml"];             return documentspath;         }     + (myviewcontroller *)parse:(nsstring *)nodesforpath:(nsstring *)elementsforname {          nsstring *filepath = [self datafilepath:false];         nsdata *xmldata = [[nsmutabledata alloc] initwithcontentsoffile:filepath];         nserror *error;         gdataxmldocument *doc = [[gdataxmldocument alloc] initwithdata:xmldata options:0 error:&error];         if (doc == nil) { return nil; }         myviewcontroller *view = [[[myviewcontroller alloc] init] autorelease];         nsarray *getversioninfo = [doc nodesforxpath:nodesforpath error:nil];         (gdataxmlelement *versioninfo in getversioninfo) {             nsarray *elm1 = [versioninfo elementsforname:elementsforname];             gdataxmlelement *elm2 = (gdataxmlelement *) [elm1 objectatindex:0];                 return elm2.stringvalue;         }          [doc release];         [xmldata release];         return view;     } 

the main problem in parse:nodesforpath:elementsforname: method. when find element looking for, returns nsstring (inside loop). when don't find element looking for, exits loop , returns instance of myviewcontroller. can't compare view controller string, causes crash.

this inexplicable. why ever that? it's not used anywhere before return it. makes no sense have code in there. cut references myviewcontroller out completely. return nil parse:nodesforpath:elementsforname: method. don't return prematurely within loop without releasing allocated memory or memory leak. there's leak in earlier return too.


Comments

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -