使用@property和@synthesise? [英] use of @property and @synthesise?

查看:128
本文介绍了使用@property和@synthesise?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道@property和@synthesise有什么意义。目前我使用以下内容声明:

I was wondering what the point of @property and @synthesise were. At the moment I use the following to declare something:

//Class.m
#import "Class.h"

CCNode *node;

@implementation
//init, etc..

但我见过其他人使用:

@property (nonatomic, etc..) CCNode* node;
@synthesise (nonatomic, etc..) node;
//I am not too sure on how this type of declaration works, please correct me on how it's done.

它们似乎都以相同的方式工作,@ property和@synthesise有什么优点办法?他们做不同的事情,如果有的话,是什么?

They both seem to work in the same way, what are the advantages of the @property and @synthesise way? Do they do different things, if so, what?

推荐答案

@property @synthesize 是两个客观的C关键字,允许您轻松创建属性,从而避免手动编写属性的getter和setter方法。

@property and @synthesize are two objective C keyword that allow you to easily create your properties and therefore avoid to write by hand getters and setters methods of the property.

@property 定义属性本身,应放在头文件中并获取一些属性(例如:strong,应该将 @synthesize 置于实现文件中,并告诉编译器生成getter和setter方法的主体。

The @property define the property itself, should be placed in the header file and can get some attributes (as for example : strong, nonatomic, retain assign, copy), the @synthesize should be placed into the implementation file and tell the compiler to generate the body of getter and setter method.

这两个关键字非常有用与正确使用其属性相结合,因为它们负责生成属性代码并且大多数他们只负责物业的内存管理。

These two keyword are extremely useful when coupled with the right use of their attributes, because they take care of the generation of the property code and most of all they take care of the memory management of the property.

这篇关于使用@property和@synthesise?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆