             realm.add(newDeck)
         }
         
+        deckDBChanged = true
+        
         return id
     }
 

    private var decks = [Deck]()
    // private var flashcards = [Flashcard]()
    private let realm = try! Realm()
    
    init(){
        // usuwanie tylko wtedy gdy jest internet i najpewniej nie w tym miejscu. Na razie ze względu na 
        // DummyData
        // TODO: relocate removeDecksFromDatabase() and check for internet connection
        removeDecksFromDatabase()
        
    }
    
    func decks(sorted:Bool )->[Deck] {
        
        // load all Deck from database to memory, if not loaded
        loadDecksFromDatabase()

        if (sorted){
            return decks.sort {

            try! realm.write {
                updatingDeck.name = deck.name
            }
            
            deckDBChanged = true
            
        }else {
            DataManagerError.NoDeckWithGivenId
        }
