Creating instance variables in the .h


#1

I’ve been told, that in the newer versions of Xcode, with the newer frameworks (don’t know as of which version), it’s not necessary anymore to declare your instance variables in the .h, the way it is done in the beginning of this chapter, in the Employee.h. So I’ve changed my code from

[code]#import “Person.h”

@interface Employee : Person
{
int employeeID;
}
@property int employeeID;
@end
[/code]
to

[code]#import “Person.h”

@interface Employee : Person
@property int employeeID;
@end
[/code]

and that works too. Is there a reason that in the book the longer way of coding is done?

And something else: in Employee.h I didn’t import Foundation.h anymore, as I import Person.h and Foundation.h is imported there already. Is that correct?


#2

Yes, the optional nature of declaring instance variables for properties is discussed in Chapter 30 (top of page 218).

Every project has a list of precompiled headers (look for a file ending in .pch), and this typically includes Foundation. So, it is automatically included in every source file.


#3

Thanks for the reply, and… wow, you’re fast! :wink: