gpt4 book ai didi

swift - swift 中的 Sink 协议(protocol)是什么?

转载 作者:可可西里 更新时间:2023-11-01 01:06:53 24 4
gpt4 key购买 nike

Swift header 的 Sink 协议(protocol)定义为

protocol Sink {
typealias Element
func put(x: Element)
}

什么是 Sink 协议(protocol),它应该用于 Swift 和 Cocoa 设计模式?

我唯一能说的实现这个协议(protocol)的是

struct IntEncoder : Sink {
var asInt: UInt64
var shift: UInt64
func put(x: CodeUnit)
}

最佳答案

接收器(如“厨房水槽”)代表生产者/消费者对的消费者端。它是一个抽象接口(interface),只接受某种输入。因此,任何生成对象的东西都可以被赋予一个 Sink 作为传递对象的方式。这是生产者传递对象所需的关于消费者的最少知识。

队列和集合是仅存储输入的简单接收器的示例。网络连接或记录器可以充当接收器,立即处理输入。

关于swift - swift 中的 Sink 协议(protocol)是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24164933/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com