0

I am trying to make async. request using Promisekit's promises. I have the following code in a subclass of UITableViewController, to reload tableview with data that is fetched from async. request.

my_promise.then { asynly_fetched_data in 
  self.data = asyncly_fetched_data
  self.tableView.reloadData()
} 

However, the following statement (self.tableView.reloadData()) is causing the following build error.

 Missing return in a closure expected to return 'AnyPromise' 

Is it because we cannot call reloadData() inside a closure. IF that is the case, what is the best practice to reload tableview after asynchronous request is complete.

user462455
  • 12,838
  • 18
  • 65
  • 96

1 Answers1

2

It's a swift bug. But you can fix it by adding -> Void in your closure:

my_promise.then { asynly_fetched_data -> Void in 
  self.data = asyncly_fetched_data
  self.tableView.reloadData()
} 

That way, Swift knows that the return is Void.

Christian
  • 22,585
  • 9
  • 80
  • 106
  • Thanks!! That worked. But how did you figure it out that (-> Void) fixes the issue. – user462455 Aug 18 '15 at 20:22
  • It's a known bug. I've had a similar problem before. – Christian Aug 18 '15 at 21:27
  • 2
    it's not a bug - it's how multiline closures works - compiler cannot infer return type from you code and compare it with requirement from method definition. if you left only one line - it will compile normally – sacred0x01 Jun 25 '17 at 20:01