4

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.

Sabha B
  • 2,079
  • 3
  • 28
  • 40

1 Answers1

8

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
}
Community
  • 1
  • 1
Steven Fisher
  • 44,462
  • 20
  • 138
  • 192
  • Thank you! I am wondering is there is a way we can write the same code without Class (Struct). This is kind of confusing "Class c = NSClassFromString(r);". . Let me read more about this to understand this file. – Sabha B Aug 17 '12 at 16:24
  • Found some information here http://macdevcenter.com/pub/a/mac/2002/05/24/runtime_partone.html – Sabha B Aug 17 '12 at 16:44
  • 1
    I suggest some caution here: A lot of the details of the runtime have changed from 2002. For the overall themes, the document you found will help. But in any particular detail, it may be wrong (sometimes horribly wrong). https://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/ObjCRuntimeGuide/Articles/ocrtVersionsPlatforms.html#//apple_ref/doc/uid/TP40008048-CH106 – Steven Fisher Aug 17 '12 at 16:58