• objectClasses and metaclasses


    typedef struct objc_object {
        Class isa;
    } *id;


    typedef struct objc_class *Class;
    struct objc_class {
        Class isa;
        Class super_class;
        /* followed by runtime specific details... */
    };

    Objective-C is a class-based object system. Each object is an instance of some class; the object's isa pointer points to its class. That class describes the object's data: allocation size and ivar types and layout. The class also describes the object's behavior: the selectors it responds to and instance methods it implements.

    Each Objective-C class is also an object. It has an isa pointer and other data, and can respond to selectors. When you call a "class method" like [NSObject alloc], you are actually sending a message to that class object. 


    Since a class is an object, it must be an instance of some other class: a metaclass. The metaclass is the description of the class object, just like the class is the description of ordinary instances.

    What is needed for a data structure to be an object?

    Every object has a class. This is a fundamental object-oriented concept but in Objective-C, it is also a fundamental part of the data. Any data structure which has a pointer to a class in the right location can be treated as an object.

    In Objective-C, an object's class is determined by its isa pointer. The isa pointer points to the object's Class.

    In fact, the basic definition of an object in Objective-C looks like this:

    typedef struct objc_object {
        Class isa;
    } *id;

    What this says is: any structure which starts with a pointer to a Class structure can be treated as an objc_object.

    The most important feature of objects in Objective-C is that you can send messages to them:

    What is a meta-class?

    This leads to the definition of a meta-class: the meta-class is the class for a Class object.

    Simply put:

    • When you send a message to an object, that message is looked up in the method list on the object's class.
    • When you send a message to a class, that message is looked up in the method list on the class' meta-class.

    The meta-class is essential because it stores the class methods for a Class. There must be a unique meta-class for every Class because every Class has a potentially unique list of class methods.

    https://www.cocoawithlove.com/2010/01/what-is-meta-class-in-objective-c.html

    http://www.sealiesoftware.com/blog/archive/2009/04/14/objc_explain_Classes_and_metaclasses.html

    ------------------越是喧嚣的世界,越需要宁静的思考------------------ 合抱之木,生于毫末;九层之台,起于垒土;千里之行,始于足下。 积土成山,风雨兴焉;积水成渊,蛟龙生焉;积善成德,而神明自得,圣心备焉。故不积跬步,无以至千里;不积小流,无以成江海。骐骥一跃,不能十步;驽马十驾,功在不舍。锲而舍之,朽木不折;锲而不舍,金石可镂。蚓无爪牙之利,筋骨之强,上食埃土,下饮黄泉,用心一也。蟹六跪而二螯,非蛇鳝之穴无可寄托者,用心躁也。
  • 相关阅读:
    myeclipse-9.0安装svn客户端插件
    jquery中lhgdialog插件(一)
    Jquery之ShowLoading遮罩组件
    git 命令
    org.apache.ibatis.builder.IncompleteElementException: Could not find parameter map
    在线压缩图片网址
    如何在知网下载外文文献
    Linux 常见命令
    在VIM 里面编辑和保存
    vi a.sh ABCD
  • 原文地址:https://www.cnblogs.com/feng9exe/p/15101374.html
Copyright © 2020-2023  润新知