When I analyze my code, I get the following Logic Error:
The receiver of message ‘frame’ is nil and returns a value of type ‘CGRect’ that will be garbage.
on these two lines:
CGRect rectFrame = purchaseCell.lblValue.frame;
CGRect rectFrameBG = purchaseCell.lblValueBG.frame;
The code works great, but just trying to figure out what this is saying. Am I doing something wrong?
EDIT: Here is the full method:
purchaseCell.lblHeader.font = [UIFont fontWithName:@"AvenirNextLTPro-Regular" size:16];
purchaseCell.lblHeader.text = curField.fieldName;
purchaseCell.lblValue.text = curField.fieldValue;
purchaseCell.lblValueBG.text = curField.fieldValue;
purchaseCell.lblValue.font = [UIFont fontWithName:@"AvenirNextLTPro-Regular" size:16];
purchaseCell.lblValue.backgroundColor = [UIColor clearColor];
purchaseCell.lblValueBG.textColor = [UIColor clearColor];
[purchaseCell.lblValueBG sizeToFit];
[purchaseCell.lblValue sizeToFit];
CGRect rectFrame = purchaseCell.lblValue.frame;
CGRect rectFrameBG = purchaseCell.lblValueBG.frame;
NSLog(@"RectFrame X: %.2f", rectFrame.origin.x);
purchaseCell.lblValue.frame = CGRectMake(rectFrame.origin.x-rectFrame.size.width,rectFrame.origin.y, rectFrame.size.width+14, rectFrame.size.height);
frameSizeWidth = rectFrame.size.width;
purchaseCell.lblValueBG.frame = CGRectMake(rectFrameBG.origin.x-rectFrameBG.size.width,rectFrameBG.origin.y, rectFrameBG.size.width+14, rectFrameBG.size.height);
The analyzer is saying that
evaluates to
nil, so no sensible value can be assigned torectFrame. What are you doing withpurchaseCelland it’s properties elsewhere in the code?The “receiver” means the object that is receiving the “frame” message.
It looks like there is probably some code branch where the cell or its lblValue property could be nil, and the analyser doesn’t like it. @StilesCrisis’ suggestion of checking for a nil value and returning if so will probably clear it out for you (and prevent any possible error), if you can’t find what the real cause is.