iOS — distinguish an NSDictionary from an NSMutableDictionary?

后端 未结 6 1129
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-21 14:34

I have the following code fragment:

NSString* value = @\"value\";
NSString* key = @\"key\";
NSMutableDictionary* foo = [NSMutableDictionary dictionary];
NSDictio         


        
6条回答
  •  太阳男子
    2021-01-21 15:04

    It's pretty simple actually, all you need to do is test against the member of the class, like this:

    if ([bar isMemberOfClass:[NSMutableDictionary class]]){
        [bar setValue:value forKey: key];
    }
    

    iPhone SDK difference between isKindOfClass and isMemberOfClass

提交回复
热议问题