开发者

nsdictionary objectforkey - search and get that value

I'm using NSDictionary in my iphone app. I am using "objectForKey:" method to get the value of a key. One thread (first thread) is adding key-value to a dictionary and other thread (second thread) is reading them. In second thread, i want to get a value for a key which first thread some times didn't add by that time. So, in 2nd thread i want search for some key and then get that value. Possible? What if I provide a key in dictio开发者_StackOverflownary that doesn't exist? what will it return?


You need to use NSLock to synchronize access to your dictionary, in order for your operation to be threadsafe. As for your question about the [NSDictionary -objectForKey] method, according to the documention, it will return nil if the key is not present (i.e. has no associated value) in the dictionary.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜