title: How to define code for different iOS versions
body: <p>I am working on an iOS app. I want it to support iOS 7 and 8. It is going pretty nicely, however there are lots of different parts of the app which use Apple APIs. Some of these APIs work in both iOS 8 and 7. However, some of them are deprecated in iOS 8. So I therefore went to the Apple developer site to see what to replace them with (new methods/etc....).</p>
  
  <p>However, I now have the problem that the app will work on iOS 8 fine, but certain parts of it don't work properly on iOS 7 as I'm trying to use an iOS 8 API...... (lol).</p>
  
  <p>So I just wanted to know, what is the best way to implement code which works on iOS 8 and 7. I had a few ideas (below), but I'm not sure which is best:</p>
  
  <p><strong>IDEA 1</strong></p>
  
  <p>Whenever I have code which doesn't work on both OS's, I use an if function (which calls a macro) like so:</p>
  
  <pre><code>if (SYSTEM_VERSION_LESS_THAN(@"8.0")) {
      // iOS 7 device. Use iOS 7 apis.
  }
  
  else {
     // iOS 8 (or higher) - use iOS 8 apis.
  }
  </code></pre>
  
  <p><strong>IDEA 2</strong></p>
  
  <p>I was thinking about using ifdef definitions all around the app like so:</p>
  
  <pre><code>#ifdef __IPHONE_8_0
       // iOS 8 code here....
  #else
       // iOS 7 code here....
  #endif
  </code></pre>
  
  <p>Which way is better? I would have thought that the second idea is much faster and uses less resources right?</p>
  
  <p>Or are both my ideas rubbish? Is there a much better way about solving this problem?</p>
  
  <p>Thanks for your time, Dan.</p>