This is driving me nuts. This is a mocked up version of a major issue im having in my actual project and is really frustrating me, any help would be so much appreciated. So you can copy this exact code into a blank command line app and see my issue:
i get a blank string at the end of it, and when you debug it and it goes to evaluate the if/else statements, it like crashes and blanks out, then comes back and just skipped evaluation of the whole thing. So weird and frustrating. Any help would be great!
Code:
NSMutableDictionary *loadGradeDictionary = [[NSMutableDictionary alloc] initWithCapacity:11];
[loadGradeDictionary setObject:[NSArray arrayWithObjects:@"A", @"A-", @"B+", @"B", @"B-", @"C+", @"C", @"C-", @"D+", @"D", @"D-", @"F" , nil] forKey:@"gradesArray"];
[loadGradeDictionary setObject:[NSString stringWithFormat:@"%.2f", (92.5 + 0.5)] forKey:@"A"];
[loadGradeDictionary setObject:[NSString stringWithFormat:@"%.2f", (89.5 + 0.5)] forKey:@"A-"];
[loadGradeDictionary setObject:[NSString stringWithFormat:@"%.2f", (86.5 + 0.5)] forKey:@"B+"];
[loadGradeDictionary setObject:[NSString stringWithFormat:@"%.2f", (82.5 + 0.5)] forKey:@"B"];
[loadGradeDictionary setObject:[NSString stringWithFormat:@"%.2f", (79.5 + 0.5)] forKey:@"B-"];
[loadGradeDictionary setObject:[NSString stringWithFormat:@"%.2f", (76.5 + 0.5)] forKey:@"C+"];
[loadGradeDictionary setObject:[NSString stringWithFormat:@"%.2f", (72.5 + 0.5)] forKey:@"C"];
[loadGradeDictionary setObject:[NSString stringWithFormat:@"%.2f", (69.5 + 0.5)] forKey:@"C-"];
[loadGradeDictionary setObject:[NSString stringWithFormat:@"%.2f", (66.5 + 0.5)] forKey:@"D+"];
[loadGradeDictionary setObject:[NSString stringWithFormat:@"%.2f", (62.5 + 0.5)] forKey:@"D"];
[loadGradeDictionary setObject:[NSString stringWithFormat:@"%.2f", (59.5 + 0.5)] forKey:@"D-"];
NSLog(@"\n%@", loadGradeDictionary);
float passedGrade = 90;
NSDictionary *gradeScale = loadGradeDictionary;
NSMutableString *returnString = [[NSMutableString alloc] initWithCapacity:2];
NSString *xString = [NSString stringWithFormat:@"%.2f", passedGrade];
if (([xString floatValue] > [[gradeScale valueForKey:@"A"] floatValue])) {
//return the letter here
returnString = [@"A" mutableCopy];
} else if (([[gradeScale valueForKey:@"A"] floatValue] > passedGrade) && (passedGrade > [[gradeScale valueForKey:@"A-"] floatValue])) {
//return the letter here
returnString = [@"A-" mutableCopy];
//return @"A-";
} else if (([[gradeScale valueForKey:@"A-"] floatValue] > passedGrade) && (passedGrade > [[gradeScale valueForKey:@"B+"] floatValue])) {
//return the letter here
returnString = [@"B+" mutableCopy];
//return @"B+";
} else if (([[gradeScale valueForKey:@"B+"] floatValue] > passedGrade) && (passedGrade > [[gradeScale valueForKey:@"B"] floatValue])) {
//return the letter here
returnString = [@"B" mutableCopy];
//return @"B";
} else if (([[gradeScale valueForKey:@"B"] floatValue] > passedGrade) && (passedGrade > [[gradeScale valueForKey:@"B-"] floatValue])) {
//return the letter here
returnString = [@"B-" mutableCopy];
//return @"B-";
} else if (([[gradeScale valueForKey:@"B-"] floatValue] > passedGrade) && (passedGrade > [[gradeScale valueForKey:@"C+"] floatValue])) {
//return the letter here
returnString = [@"C+" mutableCopy];
//return @"C+";
} else if (([[gradeScale valueForKey:@"C+"] floatValue] > passedGrade) && (passedGrade > [[gradeScale valueForKey:@"C"] floatValue])) {
//return the letter here
returnString = [@"C" mutableCopy];
//return @"C";
} else if (([[gradeScale valueForKey:@"C"] floatValue] > passedGrade) && (passedGrade > [[gradeScale valueForKey:@"C-"] floatValue])) {
//return the letter here
returnString = [@"C-" mutableCopy];
//return @"C-";
} else if (([[gradeScale valueForKey:@"C-"] floatValue] > passedGrade) && (passedGrade > [[gradeScale valueForKey:@"D+"] floatValue])) {
//return the letter here
returnString = [@"D+" mutableCopy];
//return @"D+";
} else if (([[gradeScale valueForKey:@"D+"] floatValue] > passedGrade) && (passedGrade > [[gradeScale valueForKey:@"D"] floatValue])) {
//return the letter here
returnString = [@"D" mutableCopy];
//return @"D";
} else if (([[gradeScale valueForKey:@"D"] floatValue] > passedGrade) && (passedGrade > [[gradeScale valueForKey:@"D-"] floatValue])) {
//return the letter here
returnString = [@"D-" mutableCopy];
//return @"D-";
} else if ([[gradeScale valueForKey:@"D-"] floatValue] > passedGrade) {
//return the letter here
returnString = [@"F" mutableCopy];
//return @"F";
}
NSLog(@"\nreturnString: %@", returnString);
i get a blank string at the end of it, and when you debug it and it goes to evaluate the if/else statements, it like crashes and blanks out, then comes back and just skipped evaluation of the whole thing. So weird and frustrating. Any help would be great!