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.

1 Answer 1

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 } 
Sign up to request clarification or add additional context in comments.

3 Comments

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.
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). developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/…

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.