J'ai cette fonction:remise à zéro étrange de NSMutableDictionary
- (NSMutableDictionary *) getUserDataDictionary
{
[userDataDicionary removeAllObjects];
userDataDicionary = [[NSMutableDictionary alloc] initWithContentsOfFile:[self getUserDataDictionaryPath]];
return 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;
}
}
}
return lastHighestIndex;
}
Le problème est:
après ce code:
MyAppDelegate *app = (MyAppDelegate *)[[UIApplication sharedApplication] delegate];
NSMutableDictionary *tmpUserData = [app getUserDataDictionary];
int lastVehicleIndex = [self getIndexOfLastVehicle];
Le tmpUserData est VIDES.
Mais quand je l'ai changé pour cela:
int lastVehicleIndex = [self getIndexOfLastVehicle];
MyAppDelegate *app = (MyAppDelegate*)[[UIApplication sharedApplication] delegate];
NSMutableDictionary *tmpUserData = [app getUserDataDictionary];
Le tmpUserData est rempli correctement.
Quelqu'un peut-il expliquer ce comportement? Merci
est-il 'nil' ou vide? –