 
         // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
         // self.navigationItem.rightBarButtonItem = self.editButtonItem()
+        let btnRefresh = UIBarButtonItem(title: "Refresh", style: UIBarButtonItemStyle.Plain, target: self, action: "loadData")
+        self.navigationItem.rightBarButtonItem = btnRefresh
         let btnAdd = UIBarButtonItem(title: "Add", style: UIBarButtonItemStyle.Done, target: self, action: "AddName")
         self.navigationItem.leftBarButtonItem = btnAdd
         self.tableView.registerClass(UITableViewCell.self, forCellReuseIdentifier: self.cellIdentifier)

    }

    
    func AddName(){
        let alert = UIAlertController(title: "New Name", message: "Add a new name", preferredStyle: .Alert)
        let saveAction = UIAlertAction(title: "Save", style: .Default, handler: {(action: UIAlertAction) -> Void in
            let textField = alert.textFields!.first
            self.Names.append(textField!.text!)
            self.tableView.reloadData()
        })
        let cancelAction = UIAlertAction(title: "Cancel", style: UIAlertActionStyle.Default) { (action:UIAlertAction) -> Void in

        self.presentViewController(alert, animated: true, completion: nil)
    }
    
    
    func saveName(name: String){
        let appDelegate = UIApplication.sharedApplication().delegate as! AppDelegate
        let managedContext = appDelegate.managedObjectContext
        let mPersonEntity = NSEntityDescription.entityForName("Person", inManagedObjectContext: managedContext)
        let mPerson = NSManagedObject(entity: mPersonEntity!, insertIntoManagedObjectContext: managedContext)
        mPerson.setValue(name, forKey: "name")
        
        do{
            try managedContext.save()
            self.people.append(mPerson)
        }catch let error as NSError{
            print("Could not save \(error), \(error.userInfo)")
        }
    }
    
    func fetchPersons(){
        let appDelegate = UIApplication.sharedApplication().delegate as! AppDelegate
        let managedContext = appDelegate.managedObjectContext
        let fetchRequest = NSFetchRequest(entityName: "Person")
        
        do{
            let results = try managedContext.executeFetchRequest(fetchRequest)
            self.people = results as! [NSManagedObject]
            self.tableView.reloadData()
        }catch let error as NSError{
            print("Could not fetch \(error), \(error.userInfo)")
        }
    }
    
    override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
        // #warning Incomplete implementation, return the number of sections
        return 1
