這是我的目標,我想得到最高的expiresDate。
struct LatestReceiptInfo {
var productId: String?
var expiresDate: Date? = nil
var isInIntroOffer_period: Bool?
var isTrialPeriod: Bool?
var cancellationDate: Date? = nil
}
latestReceiptInfoArray是我的陣列。
for latestReceiptInfo in latestReceiptInfoArray {
//2. Get the highest expire_date from latestInfoReceiptObjects array
if let exDate = latestReceiptInfo.expiresDate {
}
}
uj5u.com熱心網友回復:
如果您只查找日期,而不是日期最高的 LatestReceiptInfo ,compactMap則可以查找日期(取出零值),然后使用該max函式獲取最高日期。
let highestDate = latestReceiptInfoArray
.compactMap { $0.expiresDate }
.max()
如果您想獲得日期最高的 LatestReceiptInfo,各種方法都可以解決問題。例如,通過過濾所有實際具有日期的值。之后,您可以在比較中強制展開(yug)日期。
let highestReceiptInfo = latestReceiptInfoArray
.filter { $0.expiresDate != nil }
.max { $0.expiresDate! < $1.expiresDate! }
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/427058.html
