我想在给定索引处插入一个对象。如果索引处没有对象,我想知道。NSDictionary 是不错的选择吗?还有其他好的解决方案吗?
// Initailization
NSMutableDictionary *items = [NSMutaleDictionary dictionary];
...
// insert an object.
[items setObject:item forKey:[NSNumber numberWithInt:3]];
...
// I want to know that there is an object at a given index.
item = [items objectForKey:[NSNumber numberWithInt:4]];
if (item)
// exist
else
// non exist