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
Post a Comment