访问 NSDictionary 时的 SIGABRT
我有一个方法,每次设备位置更新时都会调用以下语句:
只是好奇为什么我从这里的 PrevSpeedDic 收到 SIGABRT 信号:
if (DriveInfoDic != nil) {
PrevSpeedDic = [DriveInfoDic objectForKey: @"speed"];
} else {
DriveInfoDic = [[NSDictionary alloc] init];
}
但是当我将其移到上面的语句上方时,它工作正常,因为它应该。我的变量定义正确,否则在任何情况下都不起作用。
DriveInfoDic = [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithDouble:speedMPH], @"speed", nil];
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];
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
默认情况下,局部变量未初始化为 0 (nil)。如果您在此之前没有设置 DriveInfoDic,它将采用第一个分支并崩溃。
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.