title: In Xamarin iOS designer, how can I prevent code from being run in ViewDidLoad?
body: <p>In the Xamarin iOS Storyboard designer, the ViewDidLoad code of the ViewController gets built and run automatically when just looking at the storyboard. This is great for programmatic design elements because I can see them in designer view without having to start the simulator, but I also need to make an API call from ViewDidLoad and that crashes the designer with the error <strong>"Custom components are not being rendered because problems were detected"</strong>.</p>
  
  <pre><code>public async override void ViewDidLoad()
  {
      base.ViewDidLoad();
  
      AddWhiteGradient();
      AddGreenGradient();
  
      await CallApi();
  }
  </code></pre>
  
  <p>In this example, I like the designer calling the <em>AddWhiteGradient()</em> and <em>AddGreenGradient()</em> functions because I can see the result of that in the storyboard, but <em>await CallApi()</em> crashes the designer.</p>
  
  <p>Is there a programmatic check to see if I'm in the designer view or not?</p>
  
  <p>Something like either:</p>
  
  <pre><code>if (!IsInDesignerView) {
      await CallApi();
  }
  </code></pre>
  
  <p><em>or</em></p>
  
  <pre><code>#if !DESIGNER
  await CallApi();
  #endif
  </code></pre>