Crystal
Crystal

Reputation: 23

XCode Class Variables

Some Obj-C instruction use variables in an extension vs having them as an ivar.
Please someone explain the difference? (and better practice for this)

@interface myClass
{
int myVar;
}

VS

@interface myClass(){
int myVar;
}

This is especially the case for the Stanford IOS online course. I don't understand why they do this instead of just using the @private in the interface (non extension).

Thank you!

Upvotes: 0

Views: 441

Answers (1)

dasdom
dasdom

Reputation: 14063

As far as I know, when you give someone access to an API you have written, you need to give them the .h file. Therefore the ivars which are private can still be seen by someone who should not care about them. When you put them into the .m file they are completely hidden and really private.

Upvotes: 3

Related Questions