ios - How to take advantage of enum string in Swift 2 or greater? -
so bellow image shows buttons in app. have enum different choices this
enum legal: string { case term = "terms of service" //link: www.google.com/terms case licenses = "licenses" //link: www.google.com/license case privacy = "privacy policy" //link: www.google.com/policy }
i want know if there efficient way store links instead of storing in variable. don't have knowledge swift memory management, know there way can away without having store links in heap using enums. may have function in enum or something.
currently passing button title , returning link accordingly
func getlinke(legal: string) -> string { if legal == legal.term.rawvalue { return "www.google.com/terms" } else if legal == legal.licenses.rawvalue { return "www.google.com/license" } else if legal == legal.privacy.rawvalue { return "www.google.com/policy" } return "" }
you totally can store link in enum, if that's need, add in enum:
var link: string { { switch self { case term: return "www.google.com/terms" case licenses: return "www.google.com/license" case privacy: return "www.google.com/policy" } } }
then can call this:
let term = legal.term let url = term.link
Comments
Post a Comment