         }
         let localNotesDictionary = convertLocalNotesToDictionaryByID(notes: localNotes)
         // Remove old notes from CoreData
-        for case let updatedNote as [String:AnyObject] in newNotes {
+        for case let updatedNote as [String:AnyObject] in updatedNotes {
             managedContext.delete(localNotesDictionary[(updatedNote["id"] as! Int)]!)
         }
         do {

            print("Error While Deleting Note: \(error.userInfo)")
        }
        // Save updated notes to CoreData
        addNotesToCoreData(notesArray: newNotes)
    }
    
    

            addNotesToCoreData(notesArray: newNotes)
        }
        if updatedNotes.count > 0 {
            updateCoreDataNotes(updatedNotes: updatedNotes)
        }
        if notesToDelete.count > 0 {
            deleteCoreDataNotes(notes: notesToDelete)
        }
    }
    
    func deleteCoreDataNotes(notes: [NSManagedObject]) {
        // Get access to CoreData managedContext
        guard let appDelegate = UIApplication.shared.delegate as? AppDelegate else { return }
        let managedContext = appDelegate.persistentContainer.viewContext
