     let context: NSManagedObjectContext
 
     private var timer: NSTimer?
+    private var counter: Counter?
 
     init(context: NSManagedObjectContext) {
         self.context = context

        if let result = context.executeFetchRequest(request, error:&error) as? [Counter] {
            if result.count < 1 {
                insert()
            }
        }
        else {
            insert()


    func update() {
        println("update")
        counter?.count++
        save()
    }

    private func insert() {
        if let entity = NSEntityDescription.entityForName("Counter", inManagedObjectContext: context),
        let counter = NSManagedObject(entity: entity, insertIntoManagedObjectContext: context) as? Counter {
            counter.count = 0
            self.counter = counter
            save()
        }
    }

    private func save() {

        var error: NSError?
        if !context.save(&error) {
            println("Error saving context: \(error)")
        }
    }

