This is from a category that I'm using to modify UIView. The code works, but in the first method (setFrameHeight) I'm using a block and in the second method (setFrameWidth) I'm not. Is there any way to use blocks more efficiently in this example?
typedef CGRect (^modifyFrameBlock)(CGRect);
- (void) modifyFrame:(modifyFrameBlock) block {
self.frame = block(self.frame);
}
- (void) setFrameWidth:(CGFloat)newWidth {
modifyFrameBlock b = ^CGRect (CGRect frame) {
frame.size.width = newWidth;
return frame;
};
[self modifyFrame:b];
}
- (void) setFrameHeight:(CGFloat)newHeight {
CGRect f = self.frame;
f.size.height = newHeight;
self.frame = f;
}
The answer may be that blocks are not appropriate for such short methods, or something. The syntax sure seems funky.