简体   繁体   English

无法在NSUSerDefault中保存双精度值

[英]Failed to save double Value in NSUSerDefault

Hi everybody :) i want to save a double Value into NSUserDefault like this: 大家好:)我想像这样将一个Double值保存到NSUserDefault中:

NSUserDefaults *startValues = [NSUserDefaults standardUserDefaults];

[startValues setDouble:[[self.dataList objectAtIndex:indexPath.row]doubleValue] forKey:@"lat"];

[startValues synchronize];

I get no Errors or Warnings from Xcode, but when i run the Code, it crashes with the Message: 我没有从Xcode收到任何错误或警告,但是当我运行代码时,它崩溃并显示消息:

-[__NSCFDictionary doubleValue]: unrecognized selector sent to instance

I also tried to split up the Code like: 我还尝试将代码拆分为:

double lat = [[self.dataList objectAtIndex:indexPath.row]doubleValue];

    [startValues setDouble:lat forKey:@"lat"];

but of course, i get the same error. 但是,当然,我得到同样的错误。 Whats the Problem? 有什么问题?

Thanks for your time and help :) 感谢您的时间和帮助:)

The problem is that [self.dataList objectAtIndex:indexPath.row] contains a dictionary. 问题是[self.dataList objectAtIndex:indexPath.row]包含字典。 NSDictionary does not understand the doubleValue message. NSDictionary无法理解doubleValue消息。

You have to somehow extract the double value from the dictionary: 您必须以某种方式从字典中提取双精度值:

NSDictionary *dictionary = self.dataList[indexPath.row];
double value = [dictionary[@"latitude"] doubleValue];
[startValues setDouble:value forKey:@"lat"];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM