13
如何檢查字典中的密鑰與方法參數中的字符串相同? 即在下面的代碼中,dictobj是NSMutableDictionary的對象,並且對於dictobj中的每個鍵我需要與字符串進行比較。如何實現這一目標?我應該鍵入NSString的鍵?在Objective-C中檢查相等性
-(void)CheckKeyWithString:(NSString *)string
{
//foreach key in NSMutableDictionary
for(id key in dictobj)
{
//Check if key is equal to string
if(key == string)// this is wrong since key is of type id and string is of NSString,Control doesn't come into this line
{
//do some operation
}
}
}
非常棒..感謝一批羅布..它的工作:) – suse 2010-02-19 03:52:06