Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Objective-c - Class Keyword

Tags:

objective-c

I didn't get the usage of "Class" in Objective-c file. It looks like this developer is mixing c++ and Objective-c (I may be wrong). I learned that we can write C functions in Objective-c code but I am not sure about this Class concept.

Since I am new to Objective-c so it would be great if someone please refer me some tutorial or book where I can learn.

like image 632
Sabha B Avatar asked Feb 20 '23 11:02

Sabha B


1 Answers

Class (with a capital C) is an Objective-C runtime type representing a class, not an instance of a class.

The documentation doesn't really offer much:

An opaque type that represents an Objective-C class.

typedef struct objc_class *Class;

Declared In

objc.h

Its most common usage is probably checking the class of an instance.

if ( [value isKindOfClass: [NSDictionary class] ) {
    // value is a dictionary
}

You could write this as:

Class dictionaryClass = [NSDictionary class];
if ( [value isKindOfClass: dictionaryClass ) {
    // value is a dictionary
}
like image 168
Steven Fisher Avatar answered Feb 21 '23 23:02

Steven Fisher