title: Storing NSDate in core data (swift)
body: <p>I'm new to swift and I'm trying to understand parts of it. I've been working on an app where I need to store a date, and I just can't figure it out.</p>
  
  <p>Any input would be great.</p>
  
  <p><em>Code to store date</em></p>
  
  <pre><code>var appDel: AppDelegate = (UIApplication.sharedApplication().delegate as! AppDelegate)
  var context: NSManagedObjectContext = appDel.managedObjectContext!
  // Users = Entity in core data
  var newuser = NSEntityDescription.insertNewObjectForEntityForName("Users",inManagedObjectContext: context) as! NSManagedObject
  // datetostore = attribute of type date
  newuser.setValue(NSDate(), forKey: "datetostore")
  context.save(nil)
  </code></pre>
  
  <p><em>Code to get stored data from Core Data</em></p>
  
  <pre><code>var appDel: AppDelegate = (UIApplication.sharedApplication().delegate as! AppDelegate)
  var context: NSManagedObjectContext = appDel.managedObjectContext!
  var request = NSFetchRequest(entityName: "Users")
  var results: NSArray = context.executeFetchRequest(request, error: nil)!
  var end: AnyObject = results[0]
  var end2 = end as! NSObject
  var end3 = end2 as! NSDate
  </code></pre>
  
  <p><strong>Please note</strong>: I know the end doesn't really work because that's where I get an error. </p>