     func removeAllEntity(entityName: String, predicate: NSPredicate? = nil) -> Bool {
         guard let items = fetchEntity(entityName, predicate: predicate) else { return true }
         
-        for item in items {
-            managedObjectContext.deleteObject(item)
-        }
-        
-        return saveContext()
+        let moc = currentManagedObjectContext
+        
+        moc.performBlockAndWait {
+            for item in items {
+                moc.deleteObject(item)
+            }
+        }
+        
+        return saveThreadContext(moc)
     }
     
     func insertOrUpdateOneEntity<T: NSManagedObject>(entityName: String,

        
        let fetchRequest = fetchForEntity(entityName, predicate: predicate, sort: sort, pageSize: pageSize, pageIndex: pageIndex)
        
        do {
            let items = try managedObjectContext.executeFetchRequest(fetchRequest) as? [T]
            return items
        }
        catch let error as NSError {
            Log.error?.message("fetch fail, \(error.localizedDescription)")
        }
        
        return nil
    }
    
    func fetchOneEntity<T: NSManagedObject>(entityName: String,

    
    func countForEntity(entityName: String, predicate: NSPredicate? = nil) -> Int? {
        
        var result: Int? = nil
        managedObjectContext.performBlockAndWait { 
            var error: NSError? = nil
            
            result = self.managedObjectContext.countForFetchRequest(self.countForEntity(entityName, predicate: predicate), error: &error)
            if let error = error {
                Log.error?.message("fetch count fail, \(error.localizedDescription)")
            }
        }
        
        return result
