s3协议和swift协议_Swift中的协议

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 :

有了协议,您可以定义一组公共属性和行为的混凝土类型实现🤓。 让我们来看一个例子:

Image for post

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 :

协议可以由类,结构,或枚举被采用 -并且当另一种类型采用的协议,它是需要实现的协议中定义的方法和属性。 一旦类型实现了协议的所有成员,就说该类型符合该协议。 例如 :

Image for post

You follow the name of the named type with a colon and the nam

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值