oc使用swift中的枚举_Swift中的枚举

本文介绍了如何在Objective-C项目中使用Swift语言的枚举类型,内容来源于一篇翻译自GitConnected的文章,探讨了Swift枚举在跨语言交互中的应用。
摘要由CSDN通过智能技术生成

oc使用swift中的枚举

Enumeration is a data type that allows you to define a list of possible values. An enum allows you to create a data type with those set of values so that they can be recognised consistently throughout your app.

枚举是一种数据类型,它允许您定义可能值的列表。 枚举允许您使用这些值集创建数据类型,以便可以在整个应用程序中一致地识别它们。

In other word: It is a group of related values 💯

换句话说:它是相关值的组合

声明一个枚举 (Declaring An Enumeration)

To declare an enumeration, you list out all the possible member values as cases:

要声明一个枚举,请列出所有可能的成员值作为案例:

Image for post

You can simplify the code a bit by collapsing the case clauses down to one line, with each value separated by a comma:

您可以通过将case子句折叠为一行,并用逗号分隔每个值来稍微简化代码:

Image for post

This code creates a new enumeration called Month with 12 possible member values. The commonly accepted best practice is to start each member value with a lower case first letter, just like a property.

Ť他的代码创建了一个名为新的枚举Month 12倍可能的成员的值。 普遍接受的最佳做法是像属性一样,以

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值