gpt4 book ai didi

ios - 我怎样才能从一个 NSDictionary 调用 objectForKey 与一个键是 NSNumbers 的 int

转载 作者:行者123 更新时间:2023-11-28 20:35:05 24 4
gpt4 key购买 nike

我正在尝试从 NSDictionary 获取和设置 NSNumber 作为键。我想我正在根据这个答案做事 https://stackoverflow.com/a/6891489/194309但我下面的代码返回空值。

- (void)viewDidLoad {
[super viewDidLoad];

NSInteger const SET1 = 1;
NSInteger const SET2 = 2;


videoKeyOfTag = [[NSDictionary alloc] initWithObjectsAndKeys:
[NSNumber numberWithInt:SET1], @"well",
[NSNumber numberWithInt:SET2], @"great",
nil];
NSLog(@"to see well: %@",[videoKeyOfTag objectForKey:[NSNumber numberWithInt:SET1]]);

}

我希望在日志中看到 well: well 但是我看到了我不想要的东西:

to see well: (null)

int 开始,如何从 NSDictionary 调用 objectForKey,其中键是 NSNumber

(我最终想使用 [sender tag] 作为元键从 NSDictionary 中提取值。)

最佳答案

如果你想让数字成为键,你需要在构造函数中反转顺序:

videoKeyOfTag = [[NSDictionary alloc] initWithObjectsAndKeys:
@"well", [NSNumber numberWithInt:SET1],
@"great", [NSNumber numberWithInt:SET2],
nil];

关于ios - 我怎样才能从一个 NSDictionary 调用 objectForKey 与一个键是 NSNumbers 的 int,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10860069/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com