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 insta开发者_C百科nce 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..
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.
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;
}
精彩评论