开发者

NSMutableDictionary returns 0xffffffff instead of nil when a key doesn't exist

开发者 https://www.devze.com 2023-04-08 12:16 出处:网络
I have an NSMutableDictionary that is doing something strange: (gdb) po listenerRegistry { } (gdb) po productI开发者_Go百科D

I have an NSMutableDictionary that is doing something strange:

(gdb) po listenerRegistry
{
}
(gdb) po productI开发者_Go百科D
com.mycompany.productid
(gdb) po [listenerRegistry objectForKey:[productID stringValue]]
0xffffffff does not appear to point to a valid object.
(gdb) po [listenerRegistry class]
__NSCFDictionary
(gdb) 

According to the docs, nil is supposed to be returned for keys that aren't in the dictionary.

Has anyone else seen this before?


Answering my own question.

The objects inside the NSMutableDictionary are of the type id <MyObserverProtocol>, and it would appear that Monolo was right in his observation that the returned value looks like NSNotFound.

Apparently, Foundation classes return NSNotFound when asked for items of that type when they don't exist or aren't found (as discussed here). While the documentation lists NSArrays explicitly, I feel compelled to believe the same is happening in my case.

0

精彩评论

暂无评论...
验证码 换一张
取 消