         if let result = context.executeFetchRequest(request, error:&error) as? [Counter] {
             if result.count < 1 {
                 insert()
+                return
             }
+            // Save a reference
+            self.counter = result.first
         }
         else {
             insert()


    func update() {
        println("update")
    }

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

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


    let context: NSManagedObjectContext

    private var timer: NSTimer?
    private var counter: Counter?

    init(context: NSManagedObjectContext) {
        self.context = context
