A UIView needs to change a warning label depending on the completion handler of a custom control:
voucherInputView.completionHandler = {[weak self] (succ
The problem is that the closure is implicitly returning the result of this expression:
self?.warningLabel.alpha = 1.0
but the closure itself is declared as returning Void
.
Adding an explicit return
should resolve the problem:
UIView.animateWithDuration(NSTimeInterval(1.0), animations: { ()-> Void in
self?.warningLabel.alpha = 1.0
return
})
Antonio's solution also applies with nested closures, like doing an AFNetworking request within UITableViewRowAction handler.
override func tableView(tableView: UITableView, editActionsForRowAtIndexPath indexPath: NSIndexPath) -> [AnyObject]? {
let cleanRowAction = UITableViewRowAction(style: UITableViewRowActionStyle.Default, title: "Do Stuff", handler: {[weak self](action: UITableViewRowAction!, indexPath: NSIndexPath!) in
AFHTTPSessionManager(baseURL: NSURL(string: "http://baseurl")).PUT("/api/", parameters: nil, success: { (task: NSURLSessionDataTask!, response: AnyObject!) -> Void in
// Handle success
self?.endEditing()
return
}, failure: { (task: NSURLSessionDataTask!, error: NSError!) -> Void in
// Handle error
self?.endEditing()
return
})
return
})
cleanRowAction.backgroundColor = UIColor.greenColor()
return [cleanRowAction]
}