title: Swift package manager: How best to indicate platform dependent code?
body: <p>The Swift Package Manager (SPM) allows support for different platforms (e.g., iOS, macOS). I'm adapting a Swift library to use SPM, and the need is for some of the code for iOS and macOS to be shared, but to have some differences as well.</p>
  
  <p>I've seen a similar example of this with the Facebook libraries:
  <a href="https://github.com/facebook/facebook-ios-sdk/blob/master/Package.swift" rel="nofollow noreferrer">https://github.com/facebook/facebook-ios-sdk/blob/master/Package.swift</a>
  In that case, they use multiple targets, each with its own (independent) code. This is not an example of platform dependency, rather of target dependency.</p>
  
  <p>I see two paths forward:</p>
  
  <p>1) Have separate library targets for iOS and macOS-- and use a similar approach to Facebook, but the bulk of the code would be shared across the targets. I'm not entirely sure if SPM allows code shared across targets. A downside here is purely in terms of syntactic sugar-- naming differences. It seems unfortunate that you'd have to import say "MyLibrary_iOS" on iOS and "MyLibrary_macOS" on macOS.</p>
  
  <p>2) Have a single target for iOS and macOS, but embed conditional compilation within the source code to conditionally include/exclude specific files. This doesn't have the naming issue as above. But it seems unclean to have to do this conditional compilation.</p>
  
  <p>Any other suggestions?
  Thanks!</p>