         var dictionary = [Int:NSManagedObject]()
         for note in notes {
             dictionary[(note.value(forKeyPath: "id") as? Int)!] = note
+        }
+        return dictionary
+    }
+    
+    // Convert [AnyObject] to [id:AnyObject]
+    private func convertRemoteNotesToDictionaryByID(notes: [AnyObject]) -> [Int:AnyObject] {
+        var dictionary = [Int:AnyObject]()
+        for case let note as [String:AnyObject] in notes {
+            dictionary[note["id"] as! Int] = note as AnyObject?
         }
         return dictionary
     }

        // Remove old notes from CoreData
        for case let updatedNote as [String:AnyObject] in newNotes {
            managedContext.delete(localNotesDictionary[(updatedNote["id"] as! Int)]!)
        }
        // Save updated notes to CoreData
        addNotesToCoreData(notesArray: newNotes)

    func syncRemoteNotesToLocal(remoteNotes: [AnyObject]) {
        var newNotes = [AnyObject]()
        var updatedNotes = [AnyObject]()
        var notesToDelete = [NSManagedObject]()
        let localNotesDict = convertLocalNotesToDictionaryByID(notes: getNotesFromCoreData())
        let remoteNotesDict = convertRemoteNotesToDictionaryByID(notes: remoteNotes)
        // Remove deleted notes
        for (key, value) in localNotesDict {
            if remoteNotesDict[key] == nil {
               notesToDelete.append(value)
            }
        }
        // Updated current or add new notes
        for case let remoteNote as [String:AnyObject] in remoteNotes {
            // If exist local note for remote note
            if let localNote = localNotesDict[remoteNote["id"] as! Int] {
