title: Swift get specific NSManagedObject from entity (core data)
body: <p>I have an entity in my "<code>ProjName.xcdatamodel</code>" with the name "Questions". In this entity I have 5 attributes ("icehockey","volleyball","soccer",...), each with type <code>transformable</code>. Each row (attribute) will be filled with a NSMutableArray.
  What I want to do is to get the value of a specific attribute in this entity. This is my code:</p>
  
  <pre><code>func readQuestionsFromCore(sport:NSString) -&gt; NSMutableArray {
      var appDel:AppDelegate = (UIApplication.sharedApplication().delegate as AppDelegate)
      var context:NSManagedObjectContext = appDel.managedObjectContext!
  
      var request = NSFetchRequest(entityName: "Questions")
      request.returnsObjectsAsFaults = false
      var results: NSArray = context.executeFetchRequest(request, error: nil)!
      var qArr:NSMutableArray!
      if results.count &gt; 0 {
          var res = results[0] as NSManagedObject
          qArr = res.valueForKey("\(sport)") as NSMutableArray
          return qArr
      } else {
          qArr = []
          return qArr
      }
  }
  </code></pre>
  
  <p>This will ofcourse not work since I take out the first index of the results from the database (<code>results[0] as NSManagedObject</code>) and thus it will crash if that element is not the same as the valueForKey I'm looking for.</p>
  
  <p>How do I get the one result row that I'm looking for? I.e. "soccer", or at least can I somehow loop through the results and compare the keys of each result row so it doesn't crash when I try with the wrong key? Like something like this:</p>
  
  <pre><code>for (res) in results as NSManagedObject {
     if(res.key == "soccer") {
        qArr = res.valueForKey("soccer") as NSMutableArray
        return qArr
     }
  }
  </code></pre>
  
  <p>I hope I'm clear in my explanation!</p>