从函数返回多个值时出现Swift错误

从函数返回多个值时出现Swift错误,swift,function,Swift,Function,我不明白我做错了什么 我有一个应用程序可以加载帖子和评论。视图控制器从另一个文件请求函数,该文件返回响应?,注释 我有一个错误: 条件绑定的初始值设定项必须具有可选类型,而不是'ActionResult',[PostComment]?' 排队 if let (response, comments) = (response, comments ) 我做错了什么 评论视频控制器 注释功能 问题在于: if let (response, comments) = (response, comments

我不明白我做错了什么

我有一个应用程序可以加载帖子和评论。视图控制器从另一个文件请求函数,该文件返回响应?,注释

我有一个错误:

条件绑定的初始值设定项必须具有可选类型,而不是'ActionResult',[PostComment]?'

排队

if let (response, comments) = (response, comments )
我做错了什么

评论视频控制器

注释功能


问题在于:

if let (response, comments) = (response, comments ) {
基本上,您要做的是在赋值的右侧创建一个新的非可选元组,该元组包含两个可选组件,因此编译器会抱怨您不能将if-let与非可选类型一起使用

您实际上可以考虑,由Load CypNeStsFoST返回的元组已经在回调参数中被拆分,因此您可以分别处理响应和注释。

postComments.loadCommentForPost(id: postId) { response, comments in
    if let response = response, let comments = comments {
       if response.success == 1 {
       ...
相关:。不相关,在loadCommentsForPost中,返回语句没有意义。您可以删除return关键字,只需调用completion即可。另外,在调用loadComments的闭包中,如果响应或注释为零,您想做什么?什么也不做?
if let (response, comments) = (response, comments ) {
postComments.loadCommentForPost(id: postId) { response, comments in
    if let response = response, let comments = comments {
       if response.success == 1 {
       ...