0

I know that it is possible in Objective C to define an instance variable without a property when I use curly braces in the top of the interface or the implementation. But what is the advantage when I do that?

Patricia
  • 2,885
  • 2
  • 26
  • 32

2 Answers2

0

The most advantage is this variables actually can be private/protected/public members according to the keyword (@private/@protected/@public) you set.

Take a look at this question

Community
  • 1
  • 1
Daniyar
  • 2,975
  • 2
  • 26
  • 39
0

I think your question should be comparing to property what is the advantage of defining instance variables.

Most property is backed by a instance variables. By default, a readwrite property will be backed by an instance variable, which will be synthesized automatically by the compiler. (A readonly property won't synthesize an instance variable, it only synthesizes a getter method which a readwrite property synthesize an instance variable and a getter and a setter method)

So property provides methods that synthesized by compiler to access the instance variable. I can't say which one has any advantages, just use the one which is proper to your case.

You may need to learn more about property. Properties Encapsulate an Object’s Values

KudoCC
  • 6,912
  • 1
  • 24
  • 53