title: How to clear and redraw contents of a UIView (present inside a view controller) with swift?
body: <p>I've a <code>UIView</code> inside a <code>View Controller</code> in which I'm drawing few lines as required by my app. After a certain point of time, I want some of those lines to disappear and a few other to appear in the same view. Approach I'm using as of now is that I'm clearing the <code>UIView</code> and redrawing all the lines I want to draw in the updated view.</p>
  
  <p>Can somebody tell me what's the right way to go about it? I've gone through various questions that sound similar but it hasn't helped much. Till now I've tried things like:-</p>
  
  <pre><code>outletView.setNeedsDisplay()
  </code></pre>
  
  <p>and </p>
  
  <pre><code>let context = UIGraphicsGetCurrentContext()
  context?.clear(outletView.frame)
  </code></pre>
  
  <p>None of these seem to make any difference.</p>
  
  <p>If I call <code>viewDidLoad()</code> again since all the lines are updated now. New lines to be drawn come up but the ones that were supposed to disappear don't go away. Variables for lines are updated correctly since other logic I have which checks line variable's values is working fine after the update is supposed to happen. Only problem is with the redraw part. In fact, if I understand this correctly, problem is only with cleaning the old uiview contents. If cleaning happens properly, redraw with <code>viewDidLoad</code> will show correct lines drawn. </p>
  
  <p>P.S. I know that calling <code>viewDidLoad()</code> explicitly isn't a good practice. Hope to find a solution to this problem without having to call viewDidLoad again.</p>