enum in Swift of Type String

enum in Swift of Type String


Many a times we would like to use enum to store text value's or may be even better to store fixed messages.

Like in below case ,  we are creating a enumeration called "StringMessages" and "raw Values" are defined to be of Type "String"



    enum StringMessages : String {
       case emptyText = "InputText is Empty"
       case nonEmptyText = "Input Text is not Empty"
   }



The only requirement here is the Raw Value should be unique.

Raw Values can be String , characters , integer or floating point number types.

Raw Values of this enum can be accessed using StringMessages.emptyText.rawValue or StringMessages.nonEmptyText.rawValue.

Comments

Popular posts from this blog

hitTest on iOS to identify the view being hit

CMTimeMakeWithSeconds explained

How to set Custom Section Header in UITableView for ios sdk version greater than 6