Swift 不能将Int类型的变量分配给定义为Int的枚举
枚举在类的开头声明。然后我尝试将标记值分配给枚举;但是编译器给出的错误是:“MenuItems不能转换为Int” 你认为这里有什么问题Swift 不能将Int类型的变量分配给定义为Int的枚举,swift,enums,tags,int,Swift,Enums,Tags,Int,枚举在类的开头声明。然后我尝试将标记值分配给枚举;但是编译器给出的错误是:“MenuItems不能转换为Int” 你认为这里有什么问题 enum MenuItems : Int { case menuItemEmail = 0 case menuItemName case menuItemPassword case menuItemAddPet } func tableView(tableView: UITableView, cellForRowAtIndexP
enum MenuItems : Int {
case menuItemEmail = 0
case menuItemName
case menuItemPassword
case menuItemAddPet
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell: SettingsViewTableCell = tableView.dequeueReusableCellWithIdentifier("cell") as SettingsViewTableCell
cell.cellDescriptionText.tag = MenuItems.menuItemName
}
最后一行在编译时出错。具有原始值的枚举具有
rawValue
属性:
cell.cellDescriptionText.tag = MenuItems.menuItemName.rawValue
现在我知道了原始值的用途。非常感谢。