Pull to upgrade in Swift

I am trying to implement pull to update in an application to view a table. I looked through examples of people, and I realized that this is pretty much the point:

var refreshControl:UIRefreshControl!  

override func viewDidLoad()
{
    super.viewDidLoad()

    self.refreshControl = UIRefreshControl()
    self.refreshControl.attributedTitle = NSAttributedString(string: "Pull to refresh")
    self.refreshControl.addTarget(self, action: "refresh:", forControlEvents: UIControlEvents.ValueChanged)
    self.tableView.addSubview(refreshControl)
}

func refresh(sender:AnyObject)
{
 // Code to refresh table view  
}

However, the only examples I can find are some time ago, and I know that the language has changed a lot since then! When I try to use the code above, I get the following error next to my refreshControl declaration:

Cannot override with a stored property 'refresh control'

My first thought before reading other examples is that I would have to declare a variable like this:

var refreshControl:UIRefreshControl = UIRefreshControl()

Like me, with some other variables, but I think not. Any ideas what the problem is?

+4
source share
2 answers

UITableViewController. UITableViewController refreshControl :

@availability(iOS, introduced=6.0)
var refreshControl: UIRefreshControl?

. var .

Optional, ? !, :

refreshControl = UIRefreshControl()
refreshControl!.attributedTitle = NSAttributedString(string: "Pull to refresh")
refreshControl!.addTarget(self, action: "refresh:", forControlEvents: UIControlEvents.ValueChanged)
tableView.addSubview(refreshControl!)
+4

viewDidLoad

self.refreshControl = UIRefreshControl()
        self.refreshControl!.attributedTitle = NSAttributedString(string: "Pull to refresh")
 self.refreshControl!.addTarget(self, action: "refresh:", forControlEvents: UIControlEvents.ValueChanged)
        self.tableView.addSubview(refreshControl!)

:)

+2

All Articles