Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find out if an object is a class object rather than an instance of a class

Using the Objective-C runtime library, how do we find out if an object is a class object rather than an instance of a class?

like image 507
Boon Avatar asked Apr 09 '13 18:04

Boon


People also ask

What is the difference between a class and an object or instance?

A class is a blueprint which you use to create objects. An object is an instance of a class - it's a concrete 'thing' that you made using a specific class. So, 'object' and 'instance' are the same thing, but the word 'instance' indicates the relationship of an object to its class.

What is an object an object is an instance of a class?

an object is an element (or instance) of a class; objects have the behaviors of their class. The object is the actual component of programs, while the class specifies how instances are created and how they behave. method: a method is an action which an object is able to perform.

How do I check if an object is an instance of a given class or of a subclass of it?

isinstance() checks whether or not the object is an instance or subclass of the classinfo.

What is the difference between an object and an instance of an object?

An instance is a specific representation of an object. An object is a generic thing while an instance is a single object that has been created in memory. Usually an instance will have values assigned to it's properties that differentiates it from other instances of the type of object.


1 Answers

Easiest surefire way I know is class_isMetaClass(object_getClass(yourObject)). (This works because classes are always instances of metaclasses.)

like image 113
Chuck Avatar answered Oct 18 '22 19:10

Chuck