Porting Swift StoreKit code from iOS 9 to OS X 10.11

I am porting Swift-based StoreKit code from iOS 9 to OS X 10.11, and have run into a pile of build errors. Has anyone else has run into difficulty porting Swift-based StoreKit code, and if so, how are you coping?


Most of the build failures appear to boil down to the iOS version of the SDK having non-optionals (non-nil arrays, strings, and such), versus the OS X version having optionals. There is also a difference of initializers. This makes writing portable code in Swift quite confounding, unless I'm missing something. For example,


// Localizing the price:
    let numberFormatter = NSNumberFormatter()
    numberFormatter.formatterBehavior = .Behavior10_4
    numberFormatter.numberStyle = .CurrencyStyle
    numberFormatter.locale = product.priceLocale
    #if os(iOS)
        let price = product.price
    #elseif os(OSX)
        let price = product.price!
    #endif
   
    return numberFormatter.stringFromNumber(price)!


// Creating a payment
    #if os(iOS)
        let payment = SKPayment(product: product)
    #elseif os(OSX)
        let payment = SKPayment.paymentWithProduct(product) as! SKPayment
    #endif


The thing that has be kvetching is, these are just two of among a dozen failures, and the last thing I want to be doing is sprinking wads of #if statements in otherwise portable code. Am I missing a build setting somewhere?