Set alarm using DatePicker (swift3

My code below works that if you manually use to datePicker to match the date and time with the users date and time it will print cool. However the code does not work as a alarm. I can set the date picker ahead of the user time and when the user time matches the date pickers timer nothing prints. I just want to be able to select a date/time using date picker and when the users eventually matches the datePickers time just print cool.

import UIKit

var dateFormatter : DateFormatter!

let datePicker2 = UIDatePicker();
let date = Date()

class ViewController: UIViewController {

@IBOutlet var dateLabel: UILabel!
override func viewDidLoad() {
super.viewDidLoad()

let datePicker : UIDatePicker = UIDatePicker(frame: CGRect(x: 0,y: 330,width: self.view.frame.size.width,height: 220))
datePicker.datePickerMode = UIDatePickerMode.dateAndTime
self.view.addSubview(datePicker)

datePicker.addTarget(self, action: #selector(ViewController.change(_:)), for: UIControlEvents.valueChanged)

dateFormatter = DateFormatter()
dateFormatter.dateFormat = "YYYY-MM-dd hh:mm"
    }

    @IBAction func change(_ sender : UIDatePicker)
   {
   let pickerString = dateFormatter.string(from: sender.date)
  let nowString = dateFormatter.string(from: Date())

   dateLabel.text = pickerString
   if pickerString == nowString {
print("cool")
 }
 }}

Hi @zalubski

It is not very clear what are you trying to accomplish. And i am not sure i understand what your problem is. Can you please clarify what is a purpose of the “change” function?

Thanks