可以使用的NSDictionary,但功能都只能從CF接口:
/* define our custom key callbacks */
CFDictionaryKeyCallBacks keyCallbacks;
keyCallbacks.version = 0; /* default */
keyCallbacks.retain = 0; /* no retain performed */
keyCallbacks.release = 0; /* no release performed */
keyCallbacks.copyDescription = 0; /* potentially applicable */
keyCallbacks.equal = 0; /* potentially applicable */
keyCallbacks.hash = 0; /* potentially applicable */
/* note: if you prefer to use NSNumber for keys,
then you should use the default key callbacks.
this illustrates what you could do if you wanted to use int keys.
*/
/* define our custom value callbacks */
CFDictionaryValueCallBacks valueCallbacks;
/* see per-field comments at keyCallbacks */
valueCallbacks.version = 0;
valueCallbacks.retain = 0;
valueCallbacks.release = 0;
valueCallbacks.copyDescription = 0;
valueCallbacks.equal = 0;
CFAllocatorRef allocator = kCFAllocatorDefault;
CFIndex capacity = 0; /* no hint in this example - resizes as needed */
NSMutableDictionary * myNewDictionary = (NSMutableDictionary*)
CFDictionaryCreateMutable(allocator, capacity, &keyCallbacks, &valueCallbacks);
/*
for insertions/values/keys:
- use a pointer to the key/value if the value is larger than a pointer.
this may require dynamic memory allocation and use of reference counting
since the keys/values must live in memory as long as the dictionary exists
*/
嘿謝謝..... tat真的是一個快速的回覆......它的工作原理。 我寫的樣本只是爲了明確我的要求。 感謝您指出內存泄漏。 –