I'm trying to do an action in my app when it is a spcific date. Here is an "example"
if it is June 5, 2017 {
} else {
}
Obviously, the bold section won't work in Swift. That's the part that I'm trying to figure out. How would I accomplish this?
I'm trying to do an action in my app when it is a spcific date. Here is an "example"
if it is June 5, 2017 {
} else {
}
Obviously, the bold section won't work in Swift. That's the part that I'm trying to figure out. How would I accomplish this?
Based off of Get current date in Swift 3?
let date = Date()
let calendar = Calendar.current
let components = calendar.dateComponents([.year, .month, .day], from: date)
let year = components.year
let month = components.month
let day = components.day
if(month == 6 && day == 5 && year == 2017) { //June 5 2017
//Code
}else{
//Code
}
Make sure to use lets for performance since you don't need to change those variables.
I am assuming that you are trying to launch some of your code at a specific date. For this you may be assisted by UILocalNotification class. You just need to create a date alarm for this, and launch your code when it fires. I hope this thread would help you.
This approach works even when the user is not using your app at the specific datetime. If you are sure that user would be using your app so you can go with this answer