title: Where to put common CoreGraphics drawing code for view and PDF generation?
body: <p>I have a question concerning the placement of CoreGraphics drawing code. I have a C struct which is a representation of my model and I have a custom view class. This custom view class implements a <code>drawRect</code> and draws it using CoreGraphics.</p>
  
  <p>I now need the ability to also generate a PDF from this view to export it. It uses the exact same drawing code as used for the view.</p>
  
  <p>My solution right now is to have a separate drawing method in the custom view class and using this method in the <code>drawRect</code> method and my method to generate the PDF.</p>
  
  <p>I am not sure if this is a clean solution because the view has a function which has nothing to do with drawing on screen. However using a new custom class as my PDF generator would mean duplicating my drawing code.</p>
  
  <p>Is there a clean way to organize this common drawing code? One could use a helper object and have it as an instance variable but this would make it a bit bloated. </p>