What is Difference between id and Class data types in Objective-C?
id is a generic type for all Objective-c objects.When you declare id type variable, that variable can point to any type of Objective-C object.
Ex: id name = @"Sam";
In the above example name is an id variable which is pointing to string object.
*********************************************************************************
Class is an Objective-C data type which can point to any Class Object.
Ex: Class studentClassObject = [Student class];
In the above example studentClassObject is a Class type variable which is pointing to Student class object.
Note: id type variable can even point to class object but not vice-versa
id is a generic type for all Objective-c objects.When you declare id type variable, that variable can point to any type of Objective-C object.
Ex: id name = @"Sam";
In the above example name is an id variable which is pointing to string object.
*********************************************************************************
Class is an Objective-C data type which can point to any Class Object.
Ex: Class studentClassObject = [Student class];
In the above example studentClassObject is a Class type variable which is pointing to Student class object.
Note: id type variable can even point to class object but not vice-versa
No comments:
Post a Comment