tags:

views:

26

answers:

2

Hi..

I am noob in iPhone development..I have a query hope I you people will solve..

In every interface file(*.h file) we declare a property for every instance variable like this...

#import <UIKit/UIKit.h>


@interface Fruit : NSObject {


 NSString *name;
 NSString *description;
}

@property(nonatomic, copy) NSString *name;
@property(nonatomic, copy) NSString *description;

- (id)initWithName:(NSString*)n description:(NSString *)desc;

@end

In this, how do we decide what will be parameters for the property of a variable????

thanks in advance..

+2  A: 

For string objects, you should use "copy" or "retain".
Typically, for most other objects you will use "retain".
For scalar types (int, float, etc), use "assign".

You can read about these Property Declaration Attributes here.

gerry3
A: 

You set properties in an initialization method like so:

@implementation Fruit
@synthesize name;
@synthesize description;

- (id)initWithName:(NSString*)n description:(NSString *)desc{
    if (self=[super init]) {
        self.name=n;
        self.description=desc;
    }
    return self;
}
TechZen