Objective-c: why private ivars are not hidden from the outside access when using KVC

后端 未结 5 2289
小蘑菇
小蘑菇 2020-12-15 13:13

After trying to access ivars using KVC, I have noticed that there was no protection on private and protected ivars. It doesn\'t matter what I put a in front of the ivar (pri

5条回答
  •  无人及你
    2020-12-15 14:06

    forbid via an override of the kvc entries:

    @implementation MONObject
    
    - (id)valueForKey:(NSString *)key
    {
    /* enforce it */
        return nil;
    }
    
    - (void)setValue:(id)value forKey:(NSString *)key
    {
    /* enforce it */
    }
    
    /* and so on */
    
    @end
    

提交回复
热议问题