【发布时间】:2020-06-03 23:05:28
【问题描述】:
可以在以下操场中看到该问题。有四个已发布的值将异步更新(一个图像和三个字符串)。当所有四个都已初始化或随后更改时,将需要更新 UI。当我尝试使用 CombineLatest4 捕获此数据流时,编译器立即使用消息 Extra argument in call 反对第四个参数。 (注意:以下代码实际上并没有做任何事情,因为它只有一个发布者,但足以在 Playground 中生成错误消息。
import Combine
import UIKit
struct CustomerUpdates
{
@Published var photo: UIImage!
@Published var firstName: String!
@Published var lastName: String!
@Published var id: String!
typealias customerTuple =
( photo: UIImage,
firstName: String,
lastName: String,
id: String )
var validatedCustomer: AnyPublisher< customerTuple, Never >
{
return Publishers.CombineLatest4( $photo,
$firstName,
$lastName,
$id )
{
photo, firstName, lastName, id in
if photo == nil
|| firstName == nil
|| lastName == nil
|| id == nil
{
return nil
}
return ( photo!, firstName!, lastName!, id! )
}
.compactMap
.return( on: RunLoop.main )
}
}
我的问题是,为什么编译器会标记第四个参数(“id”)? Apple 的 CombineLatest4 通用结构文档说:
接收并结合来自四个方面的最新元素的发布者 出版商。
【问题讨论】:
标签: ios swift compiler-errors combine