Swift3新路程(1)switch case
发布时间:2020-12-14 06:43:31 所属栏目:百科 来源:网络整理
导读:enum StringCase:String { case One = "One" case Two,Three,Four,Five func discription() - String { switch self { case .One: return "One" case .Two: return "Two" case .Three: return "Three" case .Four: return "Four" case .Five: return "Five"
enum StringCase:String { case One = "One" case Two,Three,Four,Five func discription() -> String { switch self { case .One: return "One" case .Two: return "Two" case .Three: return "Three" case .Four: return "Four" case .Five: return "Five" } } } 上面的写法是正确的,编译不会报错,因为switch对所有的case做出了列举 下面的写法是错误的,编译会报错,因为switch没有所有的case做出列举,需要添加default分支 enum StringCase:String { case One = "One" case Two,Five func discription() -> String { switch self { case .One: return "One" case .Two: return "Two" case .Three: return "Three" case .Four: return "Four" } } } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |