   case PQAverage = "average:"
 }
 
-class ParrotQuery: NSObject {
-  var entity: String?
+class ParrotQuery: NSObject, NSCopying {
+  var entity: String
   
   var compound: Bool
   var limitCount: UInt
   var batchSize: UInt
   var queryOffset: UInt
   
-  var queryPerdicate: NSPredicate?
-  var sortDescriptors: Array<NSSortDescriptor>?
+  var queryPredicate: NSPredicate?
+  var sortDescriptors: Array<NSSortDescriptor>
   var expressionDescription: NSExpressionDescription?
   
   init(entity: String) {

    
    var operatorStr = op.rawValue
    var predicate = NSPredicate(format: "%@ %@ \"%@\"", argumentArray: [key, operatorStr, value])
    self.queryPerdicate = predicate
  }
  
  func query(key: String, function: PQFunction) {

    self.expressionDescription = expDescription
  }
  
  func or(query: ParrotQuery) -> ParrotQuery? {
    if (self.queryPredicate == nil || query.queryPredicate == nil) {
      println("ParrotQuery: Warning! Compound queries must have predicate!")
      return nil
    }
    var newQuery = self.copy() as ParrotQuery
    newQuery.queryPredicate = NSCompoundPredicate.orPredicateWithSubpredicates([query.queryPredicate!, self.queryPredicate!])
    newQuery.compound = true
    return newQuery;
  }
  
  func and(query: ParrotQuery) -> ParrotQuery? {
    if (self.queryPredicate == nil || query.queryPredicate == nil) {
      println("ParrotQuery: Warning! Compound queries must have predicate!")
      return nil
    }
    var newQuery = self.copy() as ParrotQuery
    newQuery.queryPredicate = NSCompoundPredicate.andPredicateWithSubpredicates([query.queryPredicate!, self.queryPredicate!])
    newQuery.compound = true
    return newQuery
  }
  
  func not() {
    if (self.queryPredicate == nil) {
      println("ParrotQuery: Warning! Compound query must have predicate!")
      return
    }
    self.queryPredicate = NSCompoundPredicate.notPredicateWithSubpredicate(self.queryPredicate!)
    self.compound = true
  }
  
  func sort(key: String, ascending: Bool) {
    var sortDescriptor = NSSortDescriptor(key: key, ascending: ascending)
    self.sortDescriptors.append(sortDescriptor)
  }
  
  func sort(key: String, ascending: Bool, comparator: NSComparator) {
    var sortDescriptor = NSSortDescriptor(key: key, ascending: ascending, comparator: comparator)
    self.sortDescriptors.append(sortDescriptor)
  }
}