为什么当我试图打开和可选的,其中有enum friendstate我得到一个错误,当我试图在下面的开关语句应用它?提供的错误是
在类型"friendState!"中找不到枚举大小写"已添加"。"
(错误在所有情况下重复)
有办法修复这个错误吗?
var usernameText : String!
var UID : Int!
var userDetails : UserState?
var buttonText : String{
switch(userDetails!.state){
case .added:
return "remove"//error occurs
case .incoming:
return "accept"//error occurs
case .outgoing:
return "cancel"//error occurs
}
}
func setup(){
ActButton.setTitle(buttonText, forState: .Normal)
}
enum friendState : Int,Printable{
case incoming,added,outgoing
var description : String{
switch(self){
case .incoming:
return "incoming"
case .added:
return "Friends"
case .outgoing:
return "outgoing"
}
}
}
class UserState : Printable , Hashable{
var uid : Int!
var username : String
var isFollowing : Bool
var state : friendState!
var RequestForUser : Request?
init( username : String, isFollowing : Bool, state : friendState, uid :Int){
self.username = username
self.isFollowing = isFollowing
self.state = state
self.uid = uid
}
var hashValue : Int {
get{
return uid
}
}
var description : String{
return "UserName: (username) Following : (isFollowing) Association: (state) n"
}
}
函数var buttonText : String
换行:
switch(userDetails!.state)
switch(userDetails!.state!)
你需要打开userDetails可选状态