title: Core Data: How do I delete all objects with an attribute in Swift?
body: <p>Say for simplicity that I have an entity named DOWJONES.  There are two attributes for every object ex AAPL and AAPL_NSDate.  ValueForKey:AAPL returns the stock price history and ValueforKey AAPL_NSDate the corresponding date.</p>
  
  <p>How can I delete the stockprice history and corresponding date <strong>quickly and efficiently</strong> in swift?<br>
  This is how I query:</p>
  
  <pre><code>var appDel:AppDelegate = UIApplication.sharedApplication().delegate as AppDelegate
      let context = (UIApplication.sharedApplication().delegate as AppDelegate).managedObjectContext!
  
      var request = NSFetchRequest(entityName: "DOWJONES")
      request.returnsObjectsAsFaults = false
      var dowjones = context.executeFetchRequest(request, error: nil)! as [DOWJONES]
      var aapl = (dowjones as NSArray).valueForKey("AAPL") as NSArray
  </code></pre>
  
  <p>As suggested from @chris-wagner this is how I could iterate over the results and delete.</p>
  
  <pre><code>func deleteCoreDataObjects(){
      var request = NSFetchRequest(entityName: "DOWJONES")
      request.returnsObjectsAsFaults = false
      var dowjones = context.executeFetchRequest(request, error: nil)!
  
      if dowjones.count &gt; 0 {
  
          for result: AnyObject in dowjones{
              context.deleteObject(result as NSManagedObject)
              println("NSManagedObject has been Deleted")
          }
          context.save(nil)
      }
  }
  </code></pre>