title: Get values from CoreData in Swift
body: <p>I am attempting to pull out and print two values from CoreData. One is speed, the other is degrees. However things don't go as planned. First up, here's part of the code:</p>
  
  <pre><code>  // Start fetching from CoreData
  
              request = NSFetchRequest(entityName: "WindData")
  
              request.returnsObjectsAsFaults = false
  
              results = context.executeFetchRequest(request, error: nil)
  
              if results!.count &gt; 0 {
  
                  for result: AnyObject in results! {
  
                      println(result)
                      println(result.speed)
                      println(result.degrees)
  
  
                  }
              }
              else {
                  println("No data")
              }
  </code></pre>
  
  <p>When I simply print results I get the values:</p>
  
  <pre><code>&lt;NSManagedObject: 0x7f944a734e80&gt; (entity: WindData; id: 0xd000000000740000 &lt;x-coredata://762EB8C2-DDCF-43F5-8DFC-FAB9A29532E1/WindData/p29&gt; ; data: {
  degrees = 190;
  speed = 8; })
  </code></pre>
  
  <p>println(result.speed) writes in the consol: 2.34181e-38
  and println(result.degrees) won't allow me to compile and tells me that AnyObject does not have a member named degrees (although it clearly does)</p>
  
  <p>Sorry for any rookie mistakes, this is my first time posting on Stackoverflow.</p>
  
  <p>Here is the full code:</p>
  
  <pre><code>    //
  //  ViewController.swift
  //  KitesurfioApp
  //
  //  Created by Lasse Kristensen on 24/10/14.
  //  Copyright (c) 2014 Lasse Kristensen. All rights reserved.
  //
  
  import UIKit
  import CoreData
  
  class ViewController: UIViewController {
  
      override func viewDidLoad() {
          super.viewDidLoad()
  
  
          // Set logo in nav bar
  
          navigationItem.titleView = UIImageView(image: UIImage(named: "logo"))
  
  
  
          // Global save values
  
          var appDel: AppDelegate = UIApplication.sharedApplication().delegate as AppDelegate
  
          var context: NSManagedObjectContext = appDel.managedObjectContext!
  
  
  
          // JSON Fetching
  
          let urlPath = "http://api.openweathermap.org/data/2.5/weather?lat=55.564120&amp;lon=12.568605"
  
          let url = NSURL(string: urlPath)
  
          let session = NSURLSession.sharedSession()
  
          let task = session.dataTaskWithURL(url!, completionHandler: {data, response, error -&gt; Void in
  
              if (error != nil) {
                  println(error)
              }
              else {
  
  
                  // Delete old entries in CoreData
  
                  var request = NSFetchRequest(entityName: "WindData")
  
                  request.returnsObjectsAsFaults = false
  
                  var results = context.executeFetchRequest(request, error: nil)
  
                  for result in results! {
  
                      context.deleteObject(result as NSManagedObject)
                      context.save(nil)
  
                  }
  
                  // Start fetching JSON
  
  
                  let jsonResult = NSJSONSerialization.JSONObjectWithData(data, options: NSJSONReadingOptions.MutableContainers, error: nil) as NSDictionary
  
  
                  var item = jsonResult["wind"] as NSDictionary
  
                  var degrees:Int = item["deg"] as NSInteger
                  var speed:Float = item["speed"] as Float
  
  
                  // Start saving JSON
  
                  var newItem = NSEntityDescription.insertNewObjectForEntityForName("WindData", inManagedObjectContext: context) as NSManagedObject
  
                  var speedValue:NSNumber = speed as NSNumber
                  var degreesValue:NSNumber = degrees as NSNumber
  
                  newItem.setValue(speedValue, forKey: "speed")
                  newItem.setValue(degreesValue, forKey: "degrees")
  
                  context.save(nil)
  
  
  
              }
  
          })
  
          task.resume()
  
          // Start fetching from CoreData
  
          var request = NSFetchRequest(entityName: "WindData")
  
          request = NSFetchRequest(entityName: "WindData")
  
          request.returnsObjectsAsFaults = false
  
          var results = context.executeFetchRequest(request, error: nil)
  
          if results!.count &gt; 0 {
  
              for result: AnyObject in results! as [WindData] {
  
                  println(result)
                  println(result.speed)
  
              }
          }
          else {
              println("No data")
          }
  
  
      }
  
      override func didReceiveMemoryWarning() {
          super.didReceiveMemoryWarning()
          // Dispose of any resources that can be recreated.
      }
  
  
  }
  </code></pre>