title: Unable to fetch data with CoreData 'NSManagedObject' has no member 'fetch'
body: <p>I am beginner in swift and Xcode 12, I am trying to implement core data correctly in my project after forgetting to check the option Core data when I have created the project , I manipulated my appDelegate.swift and also I had wrote few code lines about core data functions , but I still face problems with it like  the error type 'NSManagedObject' has no member 'fetch' for example , I feel I have not implemented core data correctly</p>
  <p>here my AppDelegate.swift after few manipulations :</p>
  <pre><code>//
  //  AppDelegate.swift
  //  Bicycall
  //
  //  Created by Jamil Joo on 1/12/2020.
  //
  
  import UIKit
  import CoreData
  
  @main
  class AppDelegate: UIResponder, UIApplicationDelegate {
  
  
  
      func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -&gt; Bool {
          // Override point for customization after application launch.
          return true
      }
  
      // MARK: UISceneSession Lifecycle
  
      func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -&gt; UISceneConfiguration {
          // Called when a new scene session is being created.
          // Use this method to select a configuration to create the new scene with.
          return UISceneConfiguration(name: &quot;Default Configuration&quot;, sessionRole: connectingSceneSession.role)
      }
  
      func application(_ application: UIApplication, didDiscardSceneSessions sceneSessions: Set&lt;UISceneSession&gt;) {
          // Called when the user discards a scene session.
          // If any sessions were discarded while the application was not running, this will be called shortly after application:didFinishLaunchingWithOptions.
          // Use this method to release any resources that were specific to the discarded scenes, as they will not return.
      }
  
      // MARK: - Core Data stack
  
      lazy var persistentContainer: NSPersistentContainer = {
          /*
           The persistent container for the application. This implementation
           creates and returns a container, having loaded the store for the
           application to it. This property is optional since there are legitimate
           error conditions that could cause the creation of the store to fail.
          */
          let container = NSPersistentContainer(name: &quot;Bicycall&quot;)
          container.loadPersistentStores(completionHandler: { (storeDescription, error) in
              if let error = error as NSError? {
                  // Replace this implementation with code to handle the error appropriately.
                  // fatalError() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development.
                   
                  /*
                   Typical reasons for an error here include:
                   * The parent directory does not exist, cannot be created, or disallows writing.
                   * The persistent store is not accessible, due to permissions or data protection when the device is locked.
                   * The device is out of space.
                   * The store could not be migrated to the current model version.
                   Check the error message to determine what the actual problem was.
                   */
                  fatalError(&quot;Unresolved error \(error), \(error.userInfo)&quot;)
              }
          })
          return container
      }()
  
      // MARK: - Core Data Saving support
  
      func saveContext () {
          let context = persistentContainer.viewContext
          if context.hasChanges {
              do {
                  try context.save()
              } catch {
                  // Replace this implementation with code to handle the error appropriately.
                  // fatalError() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development.
                  let nserror = error as NSError
                  fatalError(&quot;Unresolved error \(nserror), \(nserror.userInfo)&quot;)
              }
          }
      }
  
  }
  </code></pre>
  <p>here my controller where I have used the core data:</p>
  <pre><code>//
  //  login.swift
  //  Bicycall
  //
  //  Created by Jamil Joo on 2/12/2020.
  //
  
  import UIKit
  import CoreData
  
  class login: UIViewController {
  
      var id: Int?
      var name: String?
      var lastname: String?
      var email:String?
      var password:String?
      var phone:String?
      
      override func viewDidLoad() {
          super.viewDidLoad()
  
          self.DeleteAllData()
          // Do any additional setup after loading the view.
      }
      
      //widgets
      
      @IBOutlet weak var txtEmail: UITextField!
      
      
      @IBOutlet weak var txtPassword: UITextField!
      
      
      
      //Actions
      @IBAction func btnLogin(_ sender: Any){
  
           //get
         /*
          guard let url = URL(string: &quot;http://localhost:3000/bikes&quot;) else {
          return
          }
          let session = URLSession.shared
          session.dataTask(with: url)  { ( data , response ,error) in
              if let response = response {
                  print(response)
              }
              
              if let data = data {
                  print(data)
                  do
                  {
                      let json = try JSONSerialization.jsonObject(with: data, options: [])
                      print(json)
                  }catch{
                      print(error)
                  }
              }
              
          }.resume()
          */
          
          //post
      
          guard let url = URL(string: &quot;http://localhost:3000/login&quot;) else {
          return
          }
          
          let bodyparameters = [&quot;email&quot;: txtEmail.text, &quot;password&quot;: txtPassword.text]
         
          var request = URLRequest(url: url)
          request.httpMethod = &quot;POST&quot;
          request.addValue(&quot;application/json&quot;, forHTTPHeaderField: &quot;Content-Type&quot;)
          guard let httpBody = try? JSONSerialization.data(withJSONObject: bodyparameters, options: []) else{
              return
              }
          request.httpBody = httpBody
          let session = URLSession.shared
          session.dataTask(with: request) { (data,response,error) in
              if let response = response {
                  print(response)
              }
              
              if let data = data {
                  do {
                      //let json = try JSONSerialization.jsonObject(with: data, options: [])
                     // print(json);
                      print(data)
                      let user = try JSONDecoder().decode(User.self, from: data)
                     
                      DispatchQueue.main.async {
                          
                          self.id = user.user_id
                          self.name = user.name
                          self.lastname = user.lastname
                          self.email = user.email
                          self.password = user.password
                          self.phone = user.phone
                          
                          print(self.id!)
                          print(self.email!)
                          
                          
                          if(user.user_id != 0){
                              //self.saveUser(user)
                             self.performSegue(withIdentifier: &quot;HomeSegue&quot;, sender: &quot;nil&quot;)
                              self.saveUser()
                          }else{
                          
                              let alert = UIAlertController(title: &quot;Login Failed&quot;, message: &quot;Wrong credentials&quot;, preferredStyle: .alert)
                              alert.addAction(UIAlertAction(title: &quot;Ok&quot;, style: .default, handler: nil))
                              alert.addAction(UIAlertAction(title: &quot;Cancel&quot;, style: .cancel, handler: nil))
                              self.present(alert, animated: true)
                              
                          }
                      
                      }
                      
                  }catch{
                      print(error)
                  }
                  
              }
              
          }.resume()
          
          
      
      }
      
      
      func DeleteAllData(){
  
          let appDelegate = UIApplication.shared.delegate as! AppDelegate
          let managedContext = appDelegate.persistentContainer.viewContext
          let DelAllReqVar = NSBatchDeleteRequest(fetchRequest: NSFetchRequest&lt;NSFetchRequestResult&gt;(entityName: &quot;Users&quot;))
          do {
              try managedContext.execute(DelAllReqVar)
          }
          catch {
              print(error)
          }
      }
  
      
  
      func saveUser() {
          
          let appDelegate = UIApplication.shared.delegate as! AppDelegate
          //represente l'ORM
          let persistentContainer = appDelegate.persistentContainer
          let managedContext = persistentContainer.viewContext
          
          let entityDescription = NSEntityDescription.entity(forEntityName: &quot;Users&quot; ,  in: managedContext)
          let object = NSManagedObject(entity: entityDescription! , insertInto: managedContext )
          object.setValue(id!  ,  forKey: &quot;user_id&quot;  )
          object.setValue(email!  ,  forKey: &quot;email&quot;  )
          object.setValue(password!  ,  forKey: &quot;password&quot;  )
          object.setValue(name!  ,  forKey: &quot;name&quot;  )
          object.setValue(lastname!  ,  forKey: &quot;lastname&quot;  )
          object.setValue(phone!  ,  forKey: &quot;phone&quot;  )
          
                    do {
                    
                   try managedContext.save()
                     print(&quot;INSERT SUCCESSFULLY&quot;)
                  print(id!)
                     }
                     catch  {
                     print(&quot;INSERT ERROR&quot;)
                     }
          
      }
      
      
      func DisplayData() {
          
          
           let appDelegate = UIApplication.shared.delegate as! AppDelegate
  
              //represente l'ORM
              let persistentContainer = appDelegate.persistentContainer
              
              let managedContext = persistentContainer.viewContext     //retourne NSManagedObject toujours
              
              //la requete retourne un NSManagedObject
              let request = NSFetchRequest&lt;NSManagedObject&gt;(entityName :   &quot;Users&quot;)
              
              //execution de la requete
              do {
              let result = try  NSManagedObject.fetch(request)
              for item in result {
              favourites.append(item.value(forKey: &quot;MovieName&quot;)  as! String)
                item.value()
              }
              
                 }
                 catch {
                 print(&quot;NO DATA FOUND , Error&quot;)
                 }
  
  
      }
      
      
      
      @IBAction func btnSignup(_ sender: Any) {
          performSegue(withIdentifier: &quot;signupSegue&quot;, sender: &quot;nil&quot;)
      }
      
      override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        
      }
  </code></pre>
  <p>What I am trying to do is to repair my project CoreData and fix what can be fixed to prevent the errors I obtain in my controller</p>
  <p>ps: I have created a data model Users</p>