Jul*_*les 5 xcode cocoa-touch objective-c analyzer
我已经问了一个类似的问题,但我仍然看不出问题?
-(id)initWithKeyPadType: (int)value
{
[self setKeyPadType:value];
self = [self init];
if( self != nil )
{
//self.intKeyPadType = value;
}
return self;
}
- (id)init {
NSNumberFormatter *formatter = [[[NSNumberFormatter alloc] init]
autorelease];
decimalSymbol = [formatter decimalSeparator];
....
Run Code Online (Sandbox Code Playgroud)
警告来自上面的一行 Instance variable used while 'self' is not set to the result of '[(super or self) init...]'
您尝试做的事情在技术上是可以的,但在某些阶段您需要调用[super init]. 如果您的类的init方法执行其他方法使用的许多常见初始化initWith...,则将您的方法放在[super init]那里。init另外,在尝试使用实例变量之前,请务必确保该类已被创建。
- (id) initWithKeyPadType: (int)value
{
self = [self init]; // invoke common initialisation
if( self != nil )
{
[self setKeyPadType:value];
}
return self;
}
- (id) init
{
self = [super init]; // invoke NSObject initialisation (or whoever superclass is)
if (!self) return nil;
NSNumberFormatter *formatter = [[[NSNumberFormatter alloc] init]
autorelease];
decimalSymbol = [formatter decimalSeparator];
...
Run Code Online (Sandbox Code Playgroud)