Prevent an object from encoding some properties


Let’s say I have a custom object, like a NSButtonCell, that I want to save to a file, but without its title. There is a way to do it in ASOC, i.e. to send a myButton’s setTitle_(“”) before saving it. The title is saved as an empty string.

Is there a way to “inhibit” the coding of the title (or any other property) in the ObjC implementation? That seems strange, because the usual need to override a method is to ADD something.

  • (void)encodeWithCoder:(NSCoder *)encoder {
    [super encodeWithCoder:encoder]; ← the inherited method encodes the title. How to prevent this?

Note: this feature is not essential, but I was just wondering.


So add setting the title to “”.

I think the only way to actually prevent it from being encoded would be to re-write the encodeWithCoder method to override the super’s implementation of it – and then don’t call the super’s method. Of course, you could only do that if you had Apple’s code for that implementation, which you don’t.

I think you could make it look like you didn’t encode it by adding “self.title = nil” in the initWithCoder method.


Does not work.

Ok, it’s looking like I’m fighting the framework again. :rolleyes: I’ll do this in ASOC code. Thank you.

Did you put the “self.title=nil” after the [super initWithCoder:decoder] statement? When I tried it, it worked fine.


Hm. Of course not, I put it on the wrong place. :confused: Sorry. It works fine. Thank you :slight_smile: