且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

为什么我们要为@property声明变量

更新时间:2022-12-24 09:26:27

自iOS 4起,您可以编写

since iOS 4, you can write

@interface MyInterface : NSObject {
}

@property(assign) NSInteger myVariable; 

@implementation MyInterface
@synthesize myVariable;
@end

这意味着您可以在接口声明中省略NSInteger myVaribale,只要在.m中进行合成即可(合成将创建setter,getter和instance变量)

Meaning you can omit the NSInteger myVaribale in your interface declaration as long as you synthesize it in the .m (the synthesize will create setter, getter and instance variable)

缺点是您不会在Xcode的调试器中看到myVariable的值.

A drawback is that you won't see the value of myVariable in Xcode's debugger.