ios - execute function inside enum -


i'm trying execute function inside enum, when execute code contenttype.savecontent("news") keep getting following error: use of instance member on type 'contenttype'; did mean use value of type 'contenttype' instead?. why wont run when i've set type string?

enum contenttype: string {      case news = "news"     case card = "cardstack"      func savecontent(type: string) {         switch type {         case contenttype.news.rawvalue:             print("news")         case contenttype.card.rawvalue:             print("card")         default:             break         }     }  } 

i instead of trying : in contenttype enum func :

func savecontent() {     switch self {     case .news:         print("news")     case .card:         print("cards")     } } 

in other part of code use enum :

func savecontentinclass(type: string) {     guard let contenttype = contenttype(rawvalue: type) else {         return     }     contenttype.savecontent() } 

Comments

Popular posts from this blog

javascript - Laravel datatable invalid JSON response -

java - Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; -

sql server 2008 - My Sql Code Get An Error Of Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '8:45 AM' to data type int -