0

in ViewController

@IBOutlet weak var myDatePicker: UIDatePicker!

in AppDelegate

let a = ViewController()

func applicationWillResignActive(application: UIApplication) {
    print(a.myDatePicker?.date)
}

I want to use the property myDatePicker.date from ViewController in AppDelegate.swift

but instance property value is nil how do you access the real value in the ViewController's myDatePicker.date which user picked?

Bowdzone
  • 3,827
  • 11
  • 39
  • 52
claude Mad
  • 11
  • 3
  • Possible duplicate of [view controller variables in ApplicationWillResignActive](http://stackoverflow.com/questions/18222052/view-controller-variables-in-applicationwillresignactive) –  Dec 27 '15 at 12:32

1 Answers1

0

You can store the value of datepicker in userdefaults or appdelegates variable. and update it whenever any change occurs in Datepicker date.

So whenever applicationWillResignActive called then you can get the date from user defaults or Appdelagates variable.

Parth Pandya
  • 1,460
  • 3
  • 18
  • 34
  • How can I store the value of datepicker in appdelegate? – claude Mad Dec 30 '15 at 21:58
  • Please check this answer http://stackoverflow.com/a/15050028/4030948 to see how string is stored and get from Appdelegate Property, Same thing you can do by taking NSDate property type. – Parth Pandya Dec 31 '15 at 05:40