For example:
What are the methods that can be called here data3?
realDate(datePicker.date), date(textField.text), content(textField.text)
in Core Data.
var stores: Contact!
// Contact is CoreData Entity Name.
@IBOutlet weak var label: UILabel!
ViewController viewDidLoad :
let list = [stores]
let timeSort = list.map{_ in stores?.realDate!.timeIntervalSinceNow}.filter{$0 > 0}.sort(<)
if let firstTime = timeSort.first {
_ = NSDate(timeIntervalSinceReferenceDate: firstTime!)
if timeSort.first != nil {
label.text = stores?.content
} else { }
}
I was trying to get help for writing code. There is no error, it does not display any information on the label.
Finding the future closest date to today in ExcelSelect the blank cell B2, copy and paste formula =MIN(IF(A2:A18>TODAY(),A2:A18)) into the Formula Bar, and then press Ctrl + Shift + Enter keys simultaneously. See screenshot: Then you will get the future closest date to today in cell B2.
You can use NSDate property timeIntervalSinceNow to sort your dates and get the first positive value:
edit/update:
Swift 3 introduced Date
which conforms to Comparable
protocol so it can be easily sorted now:
extension Date {
init?(_ year: Int,_ month: Int,_ day: Int) {
guard let date = DateComponents(calendar: .current, year: year, month: month, day: day, hour: 12).date else { return nil }
self = date
}
}
Playground testing:
let dateList = [Date(2018, 2, 18)!, Date(2017, 12, 31)!, Date(2018, 1, 5)!, Date(2018, 2, 14)!, Date(2018, 2, 15)!]
if let closestDate = dateList.sorted().first(where: {$0.timeIntervalSinceNow > 0}) { // "Feb 15, 2018, 12:00 PM"
print(closestDate.description(with: .current)) // Thursday, February 15, 2018 at 12:00:00 PM Brasilia Summer Time
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With