I can not understand what I did wrong
I have an app which loads posts and its comments. The view controller requests a function from an another file, which returns back (response?, comments?)
I get one error:
Initializer for conditional binding must have Optional type, not '(ActionResult?, [PostComment]?)'
For the line
if let (response, comments) = (response, comments )
What did I wrong?
commentsViewController
postComments.loadCommentForPost(id: postId) { (response, comments) in
// ERROR here: Initializer for conditional binding must have Optional type, not '(ActionResult?, [WorldMessageComment]?)'
if let (response, comments) = (response, comments ) {
if response!.success == 1 {
DispatchQueue.main.async(execute: {() -> Void in
self.comments = comments!
self.tableView.reloadData()
})
} else {
DispatchQueue.main.async(execute: {() -> Void in
self.handleResponses.displayError(title: response!.title, message: response!.message)
})
}
}
}
commentFunctions
func loadCommentsForPost(id: Int, completion: @escaping ((ActionResult?), [PostComment]?)->()){
// downloading the data and then
let comments : [PostComment] = ...
// Succesful
return completion((ActionResult(success: 1, title: responseTitle, message: responseMessage)), comments)
}
loadCommentsForPost, thatreturnstatement doesn't make sense. You can remove thereturnkeyword and just callcompletion. Also, in the closure where you callloadComments, what do you want to do if eitherresponseorcommentswasnil? Do nothing?