Skip to content

Commit

Permalink
Added #if swift(>=4.1) notation
Browse files Browse the repository at this point in the history
Thanks to Andrew Bennet for suggestion!
  • Loading branch information
mattbarker016 authored Apr 11, 2018
1 parent 207b378 commit 0b4e535
Showing 1 changed file with 25 additions and 7 deletions.
32 changes: 25 additions & 7 deletions SwiftyStoreKit/InAppReceipt.swift
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,12 @@ internal class InAppReceipt {
let filteredReceiptsInfo = filterReceiptsInfo(receipts: receipts, withProductIds: [productId])
let nonCancelledReceiptsInfo = filteredReceiptsInfo.filter { receipt in receipt["cancellation_date"] == nil }

let receiptItems = nonCancelledReceiptsInfo.compactMap { ReceiptItem(receiptInfo: $0) }
#if swift(>=4.1)
let receiptItems = nonCancelledReceiptsInfo.compactMap { ReceiptItem(receiptInfo: $0) }
#else
let receiptItems = nonCancelledReceiptsInfo.flatMap { ReceiptItem(receiptInfo: $0) }
#endif

// Verify that at least one receipt has the right product id
if let firstItem = receiptItems.first {
return .purchased(item: firstItem)
Expand Down Expand Up @@ -133,7 +138,11 @@ internal class InAppReceipt {

let receiptDate = getReceiptRequestDate(inReceipt: receipt) ?? date

let receiptItems = nonCancelledReceiptsInfo.compactMap { ReceiptItem(receiptInfo: $0) }
#if swift(>=4.1)
let receiptItems = nonCancelledReceiptsInfo.compactMap { ReceiptItem(receiptInfo: $0) }
#else
let receiptItems = nonCancelledReceiptsInfo.flatMap { ReceiptItem(receiptInfo: $0) }
#endif

if nonCancelledReceiptsInfo.count > receiptItems.count {
print("receipt has \(nonCancelledReceiptsInfo.count) items, but only \(receiptItems.count) were parsed")
Expand Down Expand Up @@ -163,12 +172,21 @@ internal class InAppReceipt {
return (expirationDate, $0)
}
} else {
return receiptItems.compactMap {
if let expirationDate = $0.subscriptionExpirationDate {
return (expirationDate, $0)
#if swift(>=4.1)
return receiptItems.compactMap {
if let expirationDate = $0.subscriptionExpirationDate {
return (expirationDate, $0)
}
return nil
}
return nil
}
#else
return receiptItems.compactMap {

This comment has been minimized.

Copy link
@AndrewBennet

AndrewBennet Apr 11, 2018

Whoops! Should be flatMap here.

if let expirationDate = $0.subscriptionExpirationDate {
return (expirationDate, $0)
}
return nil
}
#endif
}
}

Expand Down

0 comments on commit 0b4e535

Please sign in to comment.