title: Passing generic Class as argument to function in swift
body: <p>Below is my method in which there is fetch I make on a Managed object Class Appointment. I need to use same function for other similar managed object Classes. How do I pass different "Class" as parameter every time as I need. And also use it to fetch as I have currently "Appointment" Class. I might need to use Generics may be. Dont know how though. </p>
  
  <pre><code>func getAppointmentArray(aPredicate : String , aModel : Any) -&gt; [Any]
  {
      var apptArr = [Any]()
      let fetchRequest = NSFetchRequest&lt;Appointment&gt;(entityName: "Appointment")
      fetchRequest.returnsObjectsAsFaults = false
      fetchRequest.predicate = NSPredicate(format: aPredicate)
      do{
          let records = try managedObjectContext.fetch(fetchRequest)
  
          if let records = records as? [NSManagedObject]{
              if !records.isEmpty{
  
                  print("coreData apptmnt result : \(records)")
                  var appointment : Appointment?
  
                  for obj in records
                  {
  
                  }
              }else{
                  print("No records found")
                  apptArr = []
              }
          }
      }catch{
          print("Error")
           apptArr = []
      }
     return apptArr
  }
  </code></pre>