在xcode中写init函数时一般都是如下写法:
-(id) init
{
if(![super init])
{
return nil;
}
//todo
return self
}
但是analyze分析器会提示instance variable used while 'self' is not set to the result of '[(super or self) init...]
只要做如下修改就没有问题了。
-(id) init
{
self = [super init];
if(!self)
{
return nil;
}
//todo
return self
}
-(id) init
{
if(![super init])
{
return nil;
}
//todo
return self
}
但是analyze分析器会提示instance variable used while 'self' is not set to the result of '[(super or self) init...]
只要做如下修改就没有问题了。
-(id) init
{
self = [super init];
if(!self)
{
return nil;
}
//todo
return self
}
本文探讨了在Xcode中编写init函数时的最佳实践,包括如何正确使用super调用和避免实例变量未设置的问题。通过修改现有代码,确保初始化过程更加稳定和高效。

742

被折叠的 条评论
为什么被折叠?



