objective-cobjective-c-blocksivar

Block retaining self for CGFloat ivars?


I have a class with an ivar like this:

@interface MCProgressBarView() {
  CGFloat minimumForegroundWidth;
  CGFloat availableWidth;
}

later in code, I have this:

dispatch_async(dispatch_get_main_queue(), ^{

    CGRect frame = _foregroundImageView.frame;
    frame.size.width = roundf(minimumForegroundWidth + availableWidth * valor);
    _foregroundImageView.frame = frame;

    [self layoutIfNeeded];

});

The minimumForegroundWidth line of this later code shows this error:

Block implicitly retains 'self'; explicitly mention 'self' to indicate this is intended behavior

I know how to solve this for properties but what about CGFloat ivars?


Solution

  • The syntax is self->minimumForegroundWidth. Arrow rather than dot. It's going back to the fact that self is actually a pointer to struct, and -> is the the C notation for referencing members of that.