I am trying to check if a CGRect
is null
in my property getter and if it is, load a value by default, however, in my init method, when I use the property, it returns zero for all values.
Here is my getter:
- (CGRect)frame
{
if(CGRectIsNull(_frame))
_frame = CGRectMake(0,0,60,60);
return _frame;
}
- (id)init
{
self = [super initWithFrame:self.frame];
if(self)
{
//do something
}
return self;
}
I am not sure what's going on and where to look. Any help is much appreciated.
CGRectIsEmpty
is the better way to go here, but I think it's worth mentioning that you could also useCGRectEqualToRect
and compare toCGRectZero
– Hybridism