Reputation: 1907
I am refactoring some code for nullability and wondering about the edge case, when my parent init like that:
[super initWithData:data]
is returning nil on invalid data.
- (instancetype)initWithData:(NSData *)data{
if ((self = [super initWithData:data])) {
//some additional code
} else {
//invalid exit
return nil;
}
return self;
}
Will this work or is there a better way for this problem?
Upvotes: 0
Views: 27
Reputation: 257493
This will work, but you have to show this possibility in your interface as below, so clients of API be informed
- (nullable instancetype)initWithData:(NSData *)data;
Upvotes: 1