ios - Check if CGRect null in getter -
i trying check if cgrect null in property getter , if is, load value default, however, in init method, when use property, returns 0 values.
here getter:
- (cgrect)frame { if(cgrectisnull(_frame)) _frame = cgrectmake(0,0,60,60); return _frame; } - (id)init { self = [super initwithframe:self.frame]; if(self) { //do } return self; } i not sure what's going on , look. appreciated.
when create instance of class, _frame instance variable automatically initialized, before init method called. since _frame c-struct (cgrect), memory cleared zeroes. results in cgrect 0 values.
cgrectnull special, non-zero cgrect. check using cgrectisnull() never true.
using cgrectisempty more proper check this.
Comments
Post a Comment