samedi 25 avril 2015

ReactiveCocoa Issue


I'm attempting to use ReactiveCocoa in my project to handle the population of a UITableView.

When I load the data if none is available, I want to set the hidden property of tableView.backgroundView to false. Here's what I have so far:

func loadData() {
    let dataSource = tableView.dataSource as! BlockedTableViewDataSource
    let load = dataSource.load # RACSignal

    load.map {
        return ($0 as! [AnyObject]).count > 0
    }.startWith(true).distinctUntilChanged().setKeyPath("hidden", onObject: tableView.backgroundView!)

    load.subscribeError({ error in
        println(error)
    }, completed: {
        self.tableView.reloadData()
        self.refreshControl?.endRefreshing()
    })
}

This however errors out saying that I need to wait for the network request to finish. I'm using Parse to fetch the data but I'm thinking that my ReactiveCocoa code just isn't set up correctly and is causing this error. If I comment out the load.map... portion the table populates as expected.

How would one going about implementing this in the "Reactive Way"?


Aucun commentaire:

Enregistrer un commentaire