代码之家  ›  专栏  ›  技术社区  ›  mudit

iPhone操作系统中实例变量属性参数的确定

  •  0
  • mudit  · 技术社区  · 16 年前

    #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
    

    在这里,我们如何决定什么是变量属性的参数????

    提前谢谢。。

    2 回复  |  直到 16 年前
        1
  •  2
  •   gerry3    16 年前

    对于字符串对象,应该使用“copy”或“retain”。
    通常,对于大多数其他对象,您将使用“retain”。
    对于标量类型(int、float等),使用“assign”。

    here .

        2
  •  0
  •   TechZen    16 年前

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