开发者

How to decide parameters of the property of an instance variable in iPhone os

开发者 https://www.devze.com 2022-12-19 00:21 出处:网络
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...

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;
}
0

精彩评论

暂无评论...
验证码 换一张
取 消