Swift Keynote: Enumeration

  • An enumeration defines a common type for a group of related values and enables you to work with those values in a type-safe way within your code.   
    Or when a property can have its value only out of a defined set, enum is the solution which complimentary provides type-safety and auto-completion at compile time.
  • Enumerations can define initializers to provide an initial case value; can be extended to expand their functionality beyond their original implementation; can have functions and can conform to protocols to provide standard functionality.
  • Enums can have nested enums and associated values. 

    Screen Shot 2018-07-20 at 12.33.54 AM.png

  • Enums can be recursive: A recursive enumeration is an enumeration that has another instance of the enumeration as the associated value for one or more of the enumeration cases. “Indirect” keyword is used to inform the compiler about recursion.

    Screen Shot 2018-07-20 at 1.19.49 AM.png

  • Each enum case’s rawValue depends upon the raw type taken and if no raw type is not taken than rawValue wouldn’t be available. Swift’s enums don’t bound to use only integer type as a raw type, you can use StringsCharacters or even Floats instead.

Happy Coding!!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s