
enum AudIEnce { case Public case FrIEnds case Private} 如何从观众常数下面得到字符串“公共”?
let audIEnce = AudIEnce.Public不知道在哪个Swift版本中添加了这个功能,但现在(Swift 2.1),你只需要这个代码:
enum AudIEnce: String { case Public case FrIEnds case Private}let audIEnce = AudIEnce.Public.rawValue // "Public" 总结When strings are used for raw values,the implicit value for each case
is the text of that case’s name.[…]
06001
In the example above,Compasspoint.south has an implicit raw value of
“South”,and so on.You access the raw value of an enumeration case with its rawValue
property:06002
07000
以上是内存溢出为你收集整理的Swift:将枚举值转换为String?全部内容,希望文章能够帮你解决Swift:将枚举值转换为String?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)