Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/drupal/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 来自func的Swift联合收割机返回发布程序_Ios_Swift_Combine_Publisher - Fatal编程技术网

Ios 来自func的Swift联合收割机返回发布程序

Ios 来自func的Swift联合收割机返回发布程序,ios,swift,combine,publisher,Ios,Swift,Combine,Publisher,如果函数的输入参数中有错误,但它给出了一些编译错误,我想返回该函数的发布者 下面是相同的函数 func fetchList(input: String) -> AnyPublisher<List, Error> { guard let url = URL(string: input) else { return AnyPublisher(URLError(.cannotParseResponse)) }

如果函数的输入参数中有错误,但它给出了一些编译错误,我想返回该函数的发布者

下面是相同的函数

func fetchList(input: String) -> AnyPublisher<List, Error> {
    
    guard let url = URL(string: input)  else {            
        return AnyPublisher(URLError(.cannotParseResponse))
    }
   //some call for to get the List which returns publisher
}
func fetchList(输入:字符串)->AnyPublisher{
guard let url=url(字符串:输入)else{
返回AnyPublisher(URLError(.cannotParseResponse))
}
//有些人要求获取返回publisher的列表
}
错误

无法使用类型为“(URLError)”的参数列表调用类型为“AnyPublisher”的初始值设定项

摘要

如何创建发布服务器以返回错误


感谢您提供正确的提示。

AnyPublisher
需要一个
Publisher
作为其初始值设定参数,而您给它的是
URLError
。您可能想说“我想要一个立即发布错误的发布者”。为此,请使用发布服务器:

return AnyPublisher(
    Fail<List, Error>(error: URLError(.cannotParseResponse))
)
returnanypublisher(
失败(错误:URLError(.cannotParseResponse))
)