Smart Proxy Delegation

1 · Peter Steinberger · July 30, 2013, 4:28 p.m.
When calling optional delegates, the regular pattern is to check using respondsToSelector:, then actually call the method. This is straightforward and easy to understand: 1 2 3 4 id<PSPDFResizableViewDelegate> delegate = self.delegate; if ([delegate respondsToSelector:@selector(resizableViewDidBeginEditing:)]) { [delegate resizableViewDidBeginEditing:self]; } Now, this used to be three lines and now it’s four lines, because delegate is usually weak, and once you enable the relatively new Cl...