title: Core Data - NSManagedObject returning nil
body: <p>I wrote two seperate functions <code>fetchRecords</code> and <code>displayRecords</code> written in <code>Appdelegate</code> Class. <code>fetchRecords</code> function will fetch all records from the entity and it is working fine.<code>displayRecords</code> function accepts the return value from <code>fetchRecords</code> function and prints all the records one by one. <br><br>
  I have one view controller which calls these two functions to do the desired task. My problem is <code>result.count</code> in <code>displayRecords</code> shows the total number of records available in fetched records.While printing the records one by one the value is nil. </p>
  
  <pre><code>override func viewDidLoad() {
  super.viewDidLoad()
      let fetchedRecords = AppDelegate().fetchRecords(fromEntity: "Dashboard")
      AppDelegate().displayRecords(fromFetchedRecords: fetchedRecords)   
  }
  </code></pre>
  
  <p>And here is the <code>fetchRecords</code> and <code>displayRecords</code> functions written in AppDelegate Class</p>
  
  <pre><code>  func fetchRecords(fromEntity entity:String) -&gt; Array&lt;AnyObject&gt; {
      var fetchedResult:Array&lt;AnyObject&gt; = []
      let fetchRequest = NSFetchRequest()
      let entityDescription = NSEntityDescription.entityForName(entity, inManagedObjectContext: self.managedObjectContext)!
      fetchRequest.entity = entityDescription
      do{
          fetchedResult = try self.managedObjectContext.executeFetchRequest(fetchRequest)              
      }catch{
          let fetchError = error as NSError?
          print(fetchError!)
      }
     return fetchedResult
  }
  
  func displayRecords(fromFetchedRecords result:Array&lt;AnyObject&gt;) {
      print("Total records:\(result.count)")
      if (result.count &gt; 0) {
          for data in result {
          let dashboard = data as! NSManagedObject
          print("Value: \(dashboard.valueForKey("count"))")
          }
      }
  }
  </code></pre>
  
  <p>Adding my data model here
  <a href="https://i.stack.imgur.com/R3gqQ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/R3gqQ.png" alt="enter image description here"></a></p>
  
  <p>I will share the data insertion code also.</p>
  
  <pre><code>func saveDashBoardData(dictionary: Dictionary&lt;String, String&gt;) {
      print(NSFileManager.defaultManager().URLsForDirectory(.DocumentDirectory, inDomains: .UserDomainMask))
  
      //Create Manage Object
      let entityDescription: NSEntityDescription = NSEntityDescription.entityForName("Dashboard", inManagedObjectContext: self.managedObjectContext)!
      for data in dictionary {
          let dashboardObject = Dashboard(entity: entityDescription,insertIntoManagedObjectContext: self.managedObjectContext)
          dashboardObject.type  = data.0
          dashboardObject.count = data.1
          do {
              try self.managedObjectContext.save()
              print("Data saved succesfully")
          }
          catch {
              print(error)
          }
      }
  }
  </code></pre>