目标c中@property的目的 [英] purpose of @property in objective c

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

问题描述

看下面的代码;

@interface testViewController : UIViewController
{
     int age;
     UIPopoverController *popoverController;
}
@property (nonatomic , retain ) int age;
@property (nonatomic , retain ) UIPopoverController *popoverController;

@end

@property (nonatomic , retain ) int age定义int age;的吸气剂和吸气剂 和@synthesizing在实现中给出了自动生成的getter和setter实现.

@property (nonatomic , retain ) int age defines getters and setters for int age; and @synthesizing them in implemetation gives the autogenerated implementation of the getter and setter.

我不了解的是第二个.第二个属性(@property (nonatomic , retain ) UIPopoverController *popoverController;)生成什么方法? (:

what i dont understand is about the second one. what methods does the second property (@property (nonatomic , retain ) UIPopoverController *popoverController;) generate? (:

我已经看到很多程序将@property与对象一起使用,除了int,string等;

i have seen lot of programs that use @property with objects apart from int, string etc;

有什么可以引导我找到有关此问题的适当教程.

can any guide me to a proper tutorial about this.

先谢谢了. (也可以告诉我如何在stackoverflow上接受答案).

Thanks in advance. (also can somebody tell me how to accept answers on stackoverflow).

推荐答案

很难提供比

It is difficult to advise anything better then official documentation (at least you should start with reading it).

@property (nonatomic , retain ) int age;

确实应该为age ivar声明setter/getter方法,但是该行将给编译器错误,因为您无法为非对象类型声明具有keep属性的属性(更多信息,请参阅docs)

Is really supposed to declare setter/getter methods for age ivar, but that line will give compiler error as you can't declare property with retain attribute for non-object types (see docs for more details)

@property (nonatomic , retain ) UIPopoverController *popoverController;

此行与第1行没有太大不同-它也声明了popoverController ivar的setter和getter方法,并且自动合成的setter将保留它获取的popoverController.

This line does not differ much from the 1st one - it also declares setter and getter methods for popoverController ivar, and automatically synthesized setter will retain popoverController it gets

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

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