s3协议和swift协议
I have explained it from beginner to intermediate level, with code examples and snapshots. 🚀
我已经从初学者到中级级别解释了它,并提供了代码示例和快照。 🚀
With a protocol, you define a common set of properties and behaviours that concrete types implement 🤓. Let’s see an example for that :
有了协议,您可以定义一组公共属性和行为的混凝土类型实现🤓。 让我们来看一个例子:
The keyword protocol
is followed by the name of the protocol, followed by the curly braces with the members of the protocol inside.
关键字protocol
后跟protocol
名称,后跟带有协议成员的花括号。
The big difference you’ll notice is that the protocol doesn’t contain any implementation. What you’ve defined here is something like the idea of a vehicle — it’s something that can accelerate and stop. 💯
您会注意到的最大区别是该协议不包含任何实现。 您在此处定义的内容类似于车辆的概念 -它可以加速和停止。 💯
让我们了解它的语法 (Let’s understand it’s Syntax)
A protocol can be adopted by a class, struct, or enum — and when another type adopts a protocol, it’s required to implement the methods and properties defined in the protocol. Once a type implements all members of a protocol, the type is said to conform to the protocol. For example :
协议可以由类,结构,或枚举被采用 -并且当另一种类型采用的协议,它是需要实现的协议中定义的方法和属性。 一旦类型实现了协议的所有成员,就说该类型符合该协议。 例如 :
You follow the name of the named type with a colon and the nam