0

i know that this is a silly question but what is the difference between this @property declaration and the declaration inside the curly brackets, or i can just also do

@property(nonatomic, strong) NSMutableString *current

list too instead of writting it inside the curly brackets

@interface XMLParser : NSObject <NSXMLParserDelegate>
{

    NSMutableString *currentList;
    NSXMLParser *parser;
    dataFileHolder *dataCurrent;
}

@property(nonatomic, strong) NSMutableArray *listPopulated;
Mick MacCallum
  • 129,200
  • 40
  • 280
  • 281
Ace Munim
  • 325
  • 3
  • 18
  • If you declare any object inside curly brackets than that object is used only that class – Abha Aug 22 '13 at 11:37
  • so its private when i write this inside the brackets and the @properties are public, is that what u mean? – Ace Munim Aug 22 '13 at 11:40

2 Answers2

2

If you declare with the @property a getter and setter will be auto-generated based on the parameters you set for the property. In this example the setter and getter would be nonatomic, and be saved with a strong reference.

On the other hand, if you define it in curly brackets, only the variable will be created (no getters and setters)

Here is a more complete explanation than mine

Community
  • 1
  • 1
Daniel
  • 20,420
  • 10
  • 92
  • 149
0

If you declare any object inside curly brackets than that object is used only that class @interface XMLParser : NSObject {

NSMutableString *currentList;
NSXMLParser *parser;
dataFileHolder *dataCurrent;

}

But if you are declaring your object by using @property like this

@property(nonatomic, strong) NSMutableArray *listPopulated;

that means you ca use this NSMutableArray in another class also

There is relation between @property and synthesis like getter setter method @property worked as setter and @synthesis as a getter

Abha
  • 1,032
  • 1
  • 13
  • 36
  • You can use instance variables in other classes if you define them as public... – Daniel Aug 22 '13 at 11:44
  • Also, your comment about property being the setter and synthesize the getter is wrong. Synthesize generates the getter and setter defined by the property. It has been a while now since synthesize is not needed anymore though – Daniel Aug 22 '13 at 11:46
  • Also, declaring @property(nonatomic, strong) NSMutableArray *listPopulated; does not mean you can use NSMutableArray in another class, but listPopulated (as long as you include the .h) – Daniel Aug 22 '13 at 11:48
  • @property(nonatomic, strong) NSMutableArray *listPopulated; why i m not able to use this in another class. If i am declaring this in Class A and want to use in B than i am using it like A.listPopulated – Abha Aug 22 '13 at 11:49
  • listPopulated can be used in another class (as long as you include the .h). But NSMutableArray is just the type. – Daniel Aug 22 '13 at 11:50
  • NSMutableArray can always be used in classes, as long as cocoa is imported – Daniel Aug 22 '13 at 11:51
  • ya i know but saying about that "that means you ca use this NSMutableArray in another class also" mean object of that NSMutableArray is used in another class – Abha Aug 22 '13 at 11:53
  • I see, I understood you wrong then, sorry – Daniel Aug 22 '13 at 11:53
  • ya its my mistake that i wrote half thing. – Abha Aug 22 '13 at 11:54