我想了解如何在iOS编程中使用属性。 我只想在这里与人们核对,如果我得到的是正确的?如何在Obj中使用属性C
说我有一个属性
@interface Person : NSObject
@property NSString *firstName;
@end
实施
@implementation XYZPerson
@synthesize firstName;
...
@end
由此,
一)的实例变量命名为:firstName
创建
B) 每当我想用我的类中的财产,我打电话self.firstName
(或setter /吸气)
三)我可以初始化在init()方法的属性是这样的:
-(id) init {
...
[email protected]"SomeText";
...
}
我相信点我如上所述,是正确的,对吗?
是的,正确的!有关更多信息,请参阅Apple文档http://developer.apple.com/library/ios/#documentation/cocoa/conceptual/ProgrammingWithObjectiveC/EncapsulatingData/EncapsulatingData.html – 2013-07-25 11:44:28
还有一件事,请记住在init方法中使用@NSString ' – 2013-07-25 11:47:10
[我是否可以在实现中使用\ _property或self.property](http://stackoverflow.com/questions/12791851/do-i-use-property-or-self-property-in-implementation) –