swift - Enum Case not found in type -
enum operator: character { case substract = "-" case add = "+" case multiply = "*" case divide = "/" }
i have enum above , function declared below checks if have valid operator. e.g. isoperator("+")
func isoperator(_ symbol: character)-> operator? { let op = operator(rawvalue: symbol) switch op { case .substract, .add, .multiply, .divide: return op default: return nil } }
what compiler returns here "enum case not found in type" means cases defined in switch statement (.add .. etc) not available in operator type. why compiler not able find case since op operator type swift inver types atuomatically?
yes, because let op = operator(rawvalue: symbol)
optional
, in switch
case matching exact values. can apply optional
in case
while comparing. below.
func isoperator(_ symbol: character)-> operator? { let op = operator(rawvalue: symbol) switch op { case .substract?, .add?, .multiply?, .divide?: return op default: return nil } }
Comments
Post a Comment