views:

90

answers:

1

Hey I have a really simple question that needs more of just an explanation than a debug, but I have seen in the interface definitions for many class objects the keywords "@package", "@private", "@public", and then even weirder "struct {...}". I have been able to make complete programs without using any of the aforementioned, so I was hoping someone could explain to me the significance of those keywords.

Thanks

EDIT:
Wait, I understand now that the restictions of each declaration but why would you ever need to use them? And can you clarify what "struct {...}" means and how I use it? Thanks again :D

+3  A: 

Concerning Package, your Question is answered here in detail: http://stackoverflow.com/questions/772600/what-does-the-package-directive-do-in-objective-c

struct is a C construct that lets you access multiple data types under a single name.

@private restricts access to variables to the use by just this class

@protected restricts access to variables to the use by just this class and inheriting classes

@package restricts access to variables to the use by the framework

@public lets everyone acces this variable ( default in Obj-C classes)

Edit:

struct person {         /* declares struct person */
int   age;
float weight;
char  name[25];
  } adam;

struct person joe;
joe.age = 23;        /* add values */
joe.weight = 147.8;    

Concerning the restriction, its good OO Practice to restrict access to variables, known as encapsulation http://en.wikipedia.org/wiki/Encapsulation_%28object-oriented_programming%29

Gauloises
okay super! thanks :)
Dick Savagewood
no problem, you're welcome :)
Gauloises
Don't forget @protected
JeremyP
Almost forgot that one, thanks.
Gauloises