objective-c - Objective-C - KeyValuePair 类?

标签 objective-c iphone

我正在 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/

相关文章:

iphone - Paypal 错误: FILE SYSTEM CHECK FAILED

iphone - 在 Objective-C 中如何计算特定日期是一年中的哪一天?

iphone - 将图像保存到保存的照片后,相机胶卷 Assets 图像不可用

ios - 在 Objective C 中使用带有信号量的委托(delegate)方法

iphone - dispatch_async 会降低 UI 和应用程序的速度

iphone - 可编辑的表格 View 单元格

objective-c - URL验证功能改进

objective-c - 从 Objective-C 调用 Swift 单例

iphone - 使用 sendAsynchronousRequest :queue:completionHandler:? 时跟踪重定向

iphone - 如何将自定义 map 源添加到route-me?