iphone - 在 NSMutableDictionary 中存储变量值

标签 iphone ios5 objective-c-2.0

我们在 ios5 中有一个计算器应用程序,我们希望用户将自己的值设置为我们的计算器变量按钮,例如“x”或“y”。例如,用户设置“x=5”,想要计算“x + 5 =”,结果应该是10。我们如何让程序将用户定义的变量的临时值存储在NSMutableDictionary中

最佳答案

创建NSMutableDictionary,将数字转换为NSNumber并将其放入NSMutableDictionary中。

NSMutableDictionary *customValues = [NSMutableDictionary dictionary];

float value = 5;

NSNumber *number = [NSNumber numberForFloat:value];
[customValues setObject:number forKey:@"x"];

或者使用文字将上面两行替换为:

customValues[@"x"] = @(value);

或者你问的是不同的问题?

关于iphone - 在 NSMutableDictionary 中存储变量值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8874678/

相关文章:

cocoa - 数据源和 NSTableView

ios - Objective-C 和 Swift 之间字节数组的类型转换

iphone - UIImageWriteToSavedPhotosAlbum 仅保存 10 张图像中的 5 张。为什么?

iphone - 跨平台应用

ios - 隐藏广告横幅导致不再请求/显示广告

iphone - 图像旋转到左侧90度电子邮件附件iPhone

iphone - 当我将许多 UIView 作为 subview 添加到单元格时,如何使用 dequeueReusableCellWithIdentifier ?

iphone - NSFetchResultsController 委托(delegate)没有被调用

ios - 过渡到 iOS 5 时要注意什么

iphone - 我希望在 iPhone 中实现 Platinum UPnP