         self.refreshControl.addTarget(self, action: "forceUpdateDatabase", forControlEvents: .ValueChanged)
         self.tableView.addSubview(refreshControl)
         
+        cleanDatabaseForThreshold(7)
         updateUITableView(force: false)
     }
     

//

// todo: 
// * delete menu older than 14 days
// * mark food without pork and veggie food
// * upload fotos and write comments


            UIApplication.sharedApplication().networkActivityIndicatorVisible = false
        }
    }
    
    func cleanDatabaseForThreshold(threshold: Double) {
        Log("threshold is \(String(threshold))")
        let thresholdInSeconds = threshold * self.oneDayinSeconds
        let calendar = NSCalendar.currentCalendar()
        
        let threshold = calendar.components([.Year, .Month, .Day], fromDate: self.date.dateByAddingTimeInterval(-thresholdInSeconds))
        let normalizedThreshold = calendar.dateFromComponents(threshold)
        
        let fetchRequest = NSFetchRequest(entityName: "Menu")
        fetchRequest.predicate = NSPredicate(format: "date < %@", normalizedThreshold!)
        
        do {
            let result = try self.context.executeFetchRequest(fetchRequest) as! [Menu]
            result.forEach({ dish in
                self.context.deleteObject(dish)
            })
            try self.context.save()
        } catch {
            Log("Error: \(error)")
        }
    }
}

