Advertisement
Guest User

vcMain.swift

a guest
Jan 4th, 2015
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.98 KB | None | 0 0
  1. import UIKit
  2. import CoreData
  3.  
  4. class vcMain: UIViewController {
  5.  
  6. @IBOutlet var txtID: UITextField!
  7. @IBOutlet var txt1: UITextField!
  8. @IBOutlet var txt2: UITextField!
  9. @IBOutlet var txt3: UITextField!
  10. @IBOutlet var txt4: UITextField!
  11.  
  12. @IBAction func btnSave(sender: AnyObject) {
  13. var appDel:AppDelegate = (UIApplication.sharedApplication().delegate as AppDelegate)
  14. var context:NSManagedObjectContext = appDel.managedObjectContext!
  15.  
  16. var newIDlog = NSEntityDescription.insertNewObjectForEntityForName("ID", inManagedObjectContext: context) as NSManagedObject
  17. newIDlog.setValue("Saved as\(txtID)", forKey: "id")
  18. newIDlog.setValue("Saved as\(txt1)", forKey: "txt1")
  19. newIDlog.setValue("Saved as\(txt2)", forKey: "txt2")
  20. newIDlog.setValue("Saved as\(txt3)", forKey: "txt3")
  21. newIDlog.setValue("Saved as\(txt4)", forKey: "txt4")
  22.  
  23. context.save(nil)
  24.  
  25. println(newIDlog)
  26. println("Log Was Saved!")
  27. }
  28.  
  29. @IBAction func btnLoad(sender: AnyObject) {
  30. var appDel:AppDelegate = (UIApplication.sharedApplication().delegate as AppDelegate)
  31. var context:NSManagedObjectContext = appDel.managedObjectContext!
  32.  
  33. var request = NSFetchRequest(entityName: "ID")
  34. request.returnsObjectsAsFaults = false;
  35.  
  36. var results:NSArray = context.executeFetchRequest(request, error: nil)!
  37.  
  38. if(results.count > 0){
  39. for res in results{
  40. println(res)
  41. }
  42. }else{
  43. println("0 Results Returned... Maybe an Error!")
  44. }
  45.  
  46.  
  47. }
  48.  
  49. override func viewDidLoad() {
  50. super.viewDidLoad()
  51.  
  52. // Do any additional setup after loading the view.
  53. }
  54.  
  55. override func didReceiveMemoryWarning() {
  56. super.didReceiveMemoryWarning()
  57. // Dispose of any resources that can be recreated.
  58. }
  59.  
  60.  
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement