             })
         }
     }
+    
+    func bookDelegate(book: Book, favoriteValueChanged newValue: Bool) {
+        if newValue {
+            dictionary[favoritesTag]?.append(book)
+        } else {
+            dictionary[favoritesTag] = dictionary[favoritesTag]?.filter({ $0 !== book })
+        }
+        
+        isLibraryChanged = true
+
+        let favoritesArray = dictionary[favoritesTag]!.map({ favoriteBook in
+            favoriteBook.proxyForComparasion
+        })
+        
+        let userDefaults = NSUserDefaults.standardUserDefaults()
+        userDefaults.setObject(favoritesArray, forKey: favoritesUserDefaultsKey)
+    }
 }
            }
            
            sort()
        }
    }
    

                    if let image = NSURL(string: imageURL), document = NSURL(string: docURL) {
                        let book = Book(title: title, authors: authors, tags: tags, image: image, document: document)

                        if let favoritesArray = favoritesArray where favoritesArray.contains(book.proxyForComparasion) {
                            book.isFavorite = true
                            dictionary[favoritesTag]?.append(book)
                        }
                        
                        book.delegate = self
                        
                        for each in tags {
                            if self.tags.indexOf(each) == nil {
                                self.tags.append(each)
