Class internal variable placement question.

Joined
Oct 7, 2009
Messages
14
Reaction score
0
Points
1
Location
Singapore
It seems I can do:

============================
@interface MyClass:NSObject
{

}
NSString* Message;
@end
============================
and
============================
@interface MyClass:NSObject
{
NSString* Message;
}
@end
============================
and Both will work.
My question is...that being the case, what is the point of that "{}" ? What could be placed inside that cannot be place outside it ?

Thanks :)
 
Joined
Jun 25, 2005
Messages
3,231
Reaction score
112
Points
63
Location
On the road
Your Mac's Specs
2011 MBP, i7, 16GB RAM, MBP 2.16Ghz Core Duo, 2GB ram, Dual 867Mhz MDD, 1.75GB ram, ATI 9800 Pro vid
I don't know the answer, but you can't do this outside of the braces;
Code:
@public
	NSString* message;

Also note that Objective-C 2 seems to require the variable in the brackets for using the @property directive.

This is valid;
Code:
@interface MyClass : NSObject {
	NSString* message;
}
@property (retain) NSString* message;

This is not valid;
Code:
@interface MyClass : NSObject {
}
	NSString* message;
@property (retain) NSString* message;

Perhaps it is related to the use of directives.


Oddly, you can do this;
Code:
@interface MyClass : NSObject {
	NSString* message;
}
NSString* message;
 

Shop Amazon


Shop for your Apple, Mac, iPhone and other computer products on Amazon.
We are a participant in the Amazon Services LLC Associates Program, an affiliate program designed to provide a means for us to earn fees by linking to Amazon and affiliated sites.
Top