我正在 Objective C 中寻找类似于 C# 的 KeyValuePair 的类(即使没有泛型)。任何具有第一/第二对象的东西。我可以毫无问题地创建自己的,但我认为如果已经存在,则无需重新发明轮子。我自己还没有找到一个……有人知道吗?
最佳答案
所以基本上就像一个 HashMap ,对吧?
示例来自 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/