TaylorMac
TaylorMac

Reputation: 9002

SIGABRT when accessing NSDictionary

I have a method that is called every time the devices location updates with statements below included:

Just curious as to why I'm getting a SIGABRT signal from this PrevSpeedDic here:

if (DriveInfoDic != nil) {
    PrevSpeedDic = [DriveInfoDic objectForKey: @"speed"];
} else {
    DriveInfoDic = [[NSDictionary alloc] init];
}

But when I move this above the statement above it works fine as it should. My variables are defined correctly or it would not work in any circumstance.

  DriveInfoDic = [NSDictionary dictionaryWithObjectsAndKeys:
  [NSNumber numberWithDouble:speedMPH], @"speed", nil];

Upvotes: 0

Views: 455

Answers (1)

LaC
LaC

Reputation: 12824

Local variables are not initialized to 0 (nil) by default. If you don't set DriveInfoDic before that if, it's going to take the first branch and crash.

Upvotes: 3

Related Questions