从属性合成 iVar?
我可以检查一下当您执行以下操作时发生了什么(见下文)吗?我的想法是正确的,在“INTERFACE”中只有三个属性没有创建 iVar。在“实现”中,这三个属性被分配给名为 _window
、_animationTimer
和 _animationTimer
的 iVar。 _currentFrame
是由 @synthesize
命令创建的?
// INTERFACE
@interface testDelegate : NSObject ... {
}
@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, assign) NSTimer *animationTimer;
@property (nonatomic, assign) int currentFrame;
...
。
// IMPLEMENTATION
@implementation testDelegate
@synthesize window = _window;
@synthesize animationTimer = _animationTimer;
@synthesize currentFrame = _currentFrame;
...
Can I just check what is happening when you do the following (See below), I am right in thinking that no iVars are created in "INTERFACE" just three properties. In the "IMPLEMENTATION" those three properties are assigned to iVars called _window
, _animationTimer
& _currentFrame
which are created by the @synthesize
command?
// INTERFACE
@interface testDelegate : NSObject ... {
}
@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, assign) NSTimer *animationTimer;
@property (nonatomic, assign) int currentFrame;
...
.
// IMPLEMENTATION
@implementation testDelegate
@synthesize window = _window;
@synthesize animationTimer = _animationTimer;
@synthesize currentFrame = _currentFrame;
...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,这就是它的工作原理。
@synthesize
现在可以自动生成适当的实例变量以及它们的访问器。这是该语言相对较新的发展。Yep, that's how it works.
@synthesize
can now automatically generate the appropriate instance variables as well as accessors for them. It's a relatively recent development in the language.