当我@property
在没有声明ivars的情况下声明一个超类中的子类时,将其子类化并尝试使用_propertyName
子类中的超类ivar()实现getter ,xcode调用一个错误说明Use of undeclared identifier '_propertyName'
.
什么是符合最佳编程实践的解决方案?
我应该@synthesize propertyName = _propertyName
在@implementation
子类中还是
@interface SuperClass : AnotherClass
{
Type *_propertyName;
}
@property Type *propertyName;
@end
Run Code Online (Sandbox Code Playgroud)
编辑:
我确实理解属性的访问器方法的自动"综合"和编译器创建的"underbar ivars".
可以通过 接口或实现部分中SuperClass
没有任何@synthesize
ivars声明或声明来实现ivar .
进一步澄清我的案例:免责声明:内容被窃取的Alfie Hanssen代码块
@interface SuperViewController : UIViewController
@property (nonatomic, strong) UITableView * tableView; // ivar _tableView is automatically @synthesized
@end
#import "SuperViewController.h"
@interface SubViewController : SuperViewController
// Empty
@end
@implementation SubViewController
- (void)viewDidLoad
{
NSLog(@"tableView: %@", self.tableView); // …
Run Code Online (Sandbox Code Playgroud)