iPhone – Defining Enum and Dot Syntax In Objective C


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.

An enumerator is a list of predefined variables. If you’re familiar with Objective C data types like int and double, you know that you can define variables to hold or return int and double values. Enumerators are also a data type – the only different is that you create the data type. With enumerators, you can create variables that will hold only a value found only in the enumerator. Enumerators are declared with the help of the “enum” keyword

Enum is the user defined data type, it improves the speed of execution of the keyword. Here, we use “enum” by default as it assigns values range from 0,1,2,3…..


We can manually assign values to enum values

Ex :- 1) ENUM                                 
EX:- 2)   ENUM  

.h FILE:-

      @interface xyz
       NSString * str;
@ property (non atomic, retain) NS string x str;

.m file:-

@ implementation
  @(void) view did load
Ns string  * str; // str is local variable
Str = @ “hello ; is assigned to  the local variable
  Self. Str   =  @  “hello”; // hello is assigned to the instance variable.
// using of ‘dot’ syntax and messaging for the variables.
àSetting the value
       Self str = @ “hello:,
     [self. SetStr:,@ “Hello”];
àGetting the value
         Str2 = [self str];
        ( Or)
          Str2   = self. Str;
      [sup8 viewDidload];

   Note: – self is used to differentiate the coal variable and an instance method.

Dot syntax:-

    The dot syntax for getter and setter is new in objective C 2n which is a part of MAC OSX 10.5.  We can use either style (messaging or,) but choose only one for each project.

     The dot syntax should only be applied for setter and getter and not for the methods.


0 Responses on iPhone – Defining Enum and Dot Syntax In Objective C"

Leave a Message

Your email address will not be published. Required fields are marked *

Copy Rights Reserved © Mindmajix.com All rights reserved. Disclaimer.