Instance variable declaration needed with @property?


#1

Hello,

I’m working through the Chapter 7 and on page 185 (iBooks version in portrait mode – I hope these page numbers are consistent), we add:
@property (readwrite, assign) int fido;
to the .h file. However, I also noticed that the declaration of the instance variable fido is still included within the KvcFunAppDelegate @interface.

I was thinking that the ‘@property (readwrite, assign) int fido;’ command would also take care of the instance variable declaration. Is this true? Is the instance declaration needed when @property is used? I noticed that the program still works as expected if the instance declaration is removed.

Thanks!


#2

Unfortunately, no - it is on page 124 in the paperback version of the book.

[quote], we add:
@property (readwrite, assign) int fido;
to the .h file. However, I also noticed that the declaration of the instance variable fido is still included within the KvcFunAppDelegate @interface.
I was thinking that the ‘@property (readwrite, assign) int fido;’ command would also take care of the instance variable declaration. Is this true? Is the instance declaration needed when @property is used? I noticed that the program still works as expected if the instance declaration is removed. Thanks![/quote]
Back to your question - here you will find the answer. I had the same question a while ago :slight_smile:

cu
Vertex


#3

Vertex,

Thanks for the info. Very helpful. I see that the book continues to use the ivar declaration along with the @property statements, but the challenge solutions I downloaded only seem to use the @property declarations, which was rather confusing.

Thanks again!