title: Retrieving Core Data With Swift
body: <p><strong>Problem</strong></p>
  
  <p>I am new to IOS development, and have been struggling with Core Data. I am trying to create a settings page with a switch. I need to remember if this switch is turned on or off. I created a core data application, and have managed to figure out how to save the value of the switch to the attribute. The code below does this, I just can't figure out how to get the saved value of the switch back as on or off. How would I do this? Thanks!</p>
  
  <p><strong>Picture of Core Data</strong></p>
  
  <p><img src="https://i.stack.imgur.com/jQIao.png" alt="Coredata"></p>
  
  <p><strong>Code:</strong> </p>
  
  <pre><code>import UIKit
  import CoreData
  class preferencesStuff: UIViewController {
  
  override func viewDidLoad() {
      super.viewDidLoad()
  
      var appDel:AppDelegate = (UIApplication.sharedApplication().delegate as AppDelegate)
      var context:NSManagedObjectContext = appDel.managedObjectContext!
  
      var request = NSFetchRequest(entityName: "Settings")
      request.returnsObjectsAsFaults = false;
      var results:NSArray = context.executeFetchRequest(request, error: nil)!
  
      if(results.count &gt; 0){
          if results[results.count-1] as NSObject == 1 {
              println("ON")
          }
  
  
      }else{
          println("NO RESULTS")
      }
  
  }
  
  override func didReceiveMemoryWarning() {
      super.didReceiveMemoryWarning()
      // Dispose of any resources that can be recreated.
  }
  @IBOutlet weak var fractSwitchValue: UISwitch!
  
  @IBAction func fractSwitch(sender: AnyObject) {
      if fractSwitchValue.on == true {
          var appDel:AppDelegate = (UIApplication.sharedApplication().delegate as AppDelegate)
          var context:NSManagedObjectContext = appDel.managedObjectContext!
  
          var newSetting = NSEntityDescription.insertNewObjectForEntityForName("Settings", inManagedObjectContext: context) as NSManagedObject
          newSetting.setValue(true, forKey: "fractionOnOff")
  
          context.save(nil)
          //println(newSetting)
  
  
      }
      else {
          var appDel:AppDelegate = (UIApplication.sharedApplication().delegate as AppDelegate)
          var context:NSManagedObjectContext = appDel.managedObjectContext!
  
          var newSetting = NSEntityDescription.insertNewObjectForEntityForName("Settings", inManagedObjectContext: context) as NSManagedObject
          newSetting.setValue(false, forKey: "fractionOnOff")
  
          context.save(nil)
          //println(newSetting)
  
      }
  }
  </code></pre>
  
  <p>}</p>