title: How to check if CoreData is empty?
body: <p>I am trying to check if certain entity has data, so I wrote this code I am not sure if my code correct.When I check my code I found that if there is a data I got the answer that "data exist", but if there is no data compiler ignore else statement. I cannot understand why this happen.</p>
  
  <pre><code>   func entityIsEmpty()
     {
       let context = objAppDelegate.persistentContainer.viewContext
       let fetchRequest = NSFetchRequest&lt;NSFetchRequestResult&gt;.init(entityName: "myEntity")
  
       //do{
       //result = try context.fetch(fetchRequest) as! [NSManagedObject]
       result = fetchRequest as! [NSManagedObject] //ERROR
       for data in result{
  
       var obj = userNSObj()
       obj.myObject = data.value(forKey: "myAttribute") as! String
  
  
       myArray.append(obj)
          if myArray != nil{
              print("data exist")
          }else{
              print("data not exist")
          }
                          }
  
               //}catch{
               //print("Failed")
              //}
  
     } 
  </code></pre>