Making absolutely sure no one uses the ivar instead of the property

Use synthesis to create a really ugly name that will make it unmistakeable:

    @synthesize myVar=_DO_NOT_ACCESS_myVar;

There is no way in h*ll anyone is going to write:

    _DO_NOT_ACCESS_myVar = @"Hah"; // :-)
Advertisements

2 thoughts on “Making absolutely sure no one uses the ivar instead of the property

    • Not sure what you mean, but in any case the ivar is still reachable in all cases using the longer name. This technique does not make the ivar unusable.

      In your case, name it something like:

      ONLY_USE_IN_INIT_AND_DEALLOC_myIvar

      If you don’t like this, then don’t use this technique at all, and just take the chance that someone later will directly access the ivar.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s