0
在以下示例中,是否需要行NSObject *_propertyName;
?是@arnt所需的属性@synthesize propertyName = _propertyName;
.H
@interface ClassName
{
NSObject *_propertyName;
}
@property (nonatomic, retain) NSObject *propertyName;
@end
.M
@implementation ClassName
@synthesize propertyName = _propertyName;
@end
我觉得,如果我排除NSObject *_propertyName;
但保持@synthesize propertyName = _propertyName;
一切正常。下面是我在谈论的一个例子:
.H
@interface ClassName
@property (nonatomic, retain) NSObject *propertyName;
@end
.M
@implementation ClassName
@synthesize propertyName = _propertyName;
@end
我测试过,看到该属性仍然有效。我几乎总是看到包含行NSObject *_propertyName;
的代码。有什么我在这里失踪?
请在发布前进行搜索。已经有超过一半的问题涉及这个问题。这里有一个这样的:http://stackoverflow.com/questions/8330257/is-it-necessary-to-declare-ivars-in-interface-to-match-properties – 2012-01-10 18:21:51
这是一个搜索,将变得更多:http:/ /stackoverflow.com/search?q=%5Bobjc%5D+declare+ivars+for+properties其中的一些内容位于右侧的相关侧栏中,并且在您起草问题时会出现。 – 2012-01-10 18:23:21
发布此答案之前,我做了大量搜索。没有其他问题出现。抱歉转发,但我真的试图找到答案。 – Nate 2012-01-11 06:02:07