gpt4 book ai didi

objective-c - Objective-C - KeyValuePair 类?

转载 作者:太空狗 更新时间:2023-10-30 03:28:15 25 4
gpt4 key购买 nike

我正在 Objective C 中寻找类似于 C# 的 KeyValuePair 的类(即使没有泛型)。任何具有第一/第二对象的东西。我可以毫无问题地创建自己的,但我认为如果已经存在,则无需重新发明轮子。我自己还没有找到一个……有人知道吗?

最佳答案

所以基本上就像一个 HashMap ,对吧?

Use NSMutableDictionary

示例来自 here :

NSMutableDictionary *dictionary = [[NSMutableDictionary alloc] init]; 

// Add objects to a dictionary indexed by keys

[dictionary setObject:@"A Book about the Letter A" forKey:@"A"];
[dictionary setObject:@"A Book about the Letter B" forKey:@"B"];
[dictionary setObject:@"A Book about the Letter C" forKey:@"C"];

// Retrieve an object from a dictionary with a key

NSLog([dictionary objectForKey:@"B"]);

// Release a dictionary

[dictionary release];

关于objective-c - Objective-C - KeyValuePair 类?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3531373/

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