Ios Xcode4-在头文件中声明对象

Ios Xcode4-在头文件中声明对象,ios,xcode4,Ios,Xcode4,例如,我在接口brace{}中声明了一个对象,如下所示: @interface testViewController : UIViewController { IBOutlet UILabel * myLabel; } @property (retain, nonatomic) UILabel *myLabel; @end @interface testViewController : UIViewController { } @property (retain, nonatomic

例如,我在接口brace
{}
中声明了一个对象,如下所示:

@interface testViewController : UIViewController {
    IBOutlet UILabel * myLabel;
}
@property (retain, nonatomic) UILabel *myLabel;

@end
@interface testViewController : UIViewController {
}
@property (retain, nonatomic) IBOutlet UILabel *myLabel;

@end
示例二,我在inferface大括号
{}
之外声明了一个对象,如下所示:

@interface testViewController : UIViewController {
    IBOutlet UILabel * myLabel;
}
@property (retain, nonatomic) UILabel *myLabel;

@end
@interface testViewController : UIViewController {
}
@property (retain, nonatomic) IBOutlet UILabel *myLabel;

@end
我运行代码,结果是一样的,所以我想问一下,在接口brace
{}
内部或外部的对象有什么不同


谢谢

在第二个示例中,您只声明了一个属性。Xcode将自动声明对象。

现代Objective-C运行时(64位Mac OS X和iOS)将在您合成所声明的属性时为它们生成备份存储。因此,您不需要在大括号中声明它们

如果您声明的iVar不是属性,并且仅由类使用,则需要声明它们。将这些标记为private是个好主意

@interface MyClass : NSObject {
@private
    NSString *privateString;
}
@property (nonatomic, copy) NSString *publicString; // be sure to @synthesize this
@end
这是你可能的副本