iphone - Strange resetting of NSMutableDictionary -
iphone - Strange resetting of NSMutableDictionary -
i have functions:
- (nsmutabledictionary *) getuserdatadictionary { [userdatadicionary removeallobjects]; userdatadicionary = [[nsmutabledictionary alloc] initwithcontentsoffile:[self getuserdatadictionarypath]]; homecoming userdatadicionary; } - (int) getindexoflastvehicle { myappdelegate *app = (myappdelegate*)[[uiapplication sharedapplication] delegate]; nsmutabledictionary *tmpuserdata = [app getuserdatadictionary]; int lasthighestindex = -1; for(id item in [tmpuserdata allkeys]){ nsstring *keyinarray = (nsstring *)item; if ([keyinarray rangeofstring:@"vehicle-"].location != nsnotfound) { //f.e. "vehicle", "1", "type"...or "vehicle", "1", "spz"...or "vehicle", "2", "type" etc nsarray * separatedcomponents = [keyinarray componentsseparatedbystring:@"-"]; int indexofvehicle = [(nsstring *)[separatedcomponents objectatindex:1] intvalue]; if(indexofvehicle > lasthighestindex){ lasthighestindex = indexofvehicle; } } } homecoming lasthighestindex; }
the problem is: after code:
myappdelegate *app = (myappdelegate *)[[uiapplication sharedapplication] delegate]; nsmutabledictionary *tmpuserdata = [app getuserdatadictionary]; int lastvehicleindex = [self getindexoflastvehicle];
the tmpuserdata empty.
but when changed order this:
int lastvehicleindex = [self getindexoflastvehicle]; myappdelegate *app = (myappdelegate*)[[uiapplication sharedapplication] delegate]; nsmutabledictionary *tmpuserdata = [app getuserdatadictionary];
the tmpuserdata correctly filled.
can explain behavior? thanks
one of problems lies in method getuserdatadictionary
. calling removeallobjects
not releases userdatadictionary. have release instead of removingallobject. actual release release it's objects you.
iphone objective-c nsmutabledictionary
Comments
Post a Comment