Objective-c Sunflower Treasure Book First Heavy (internal)--Class and object

Source: Internet
Author: User

 Objective-c Sunflower Treasure Book First Heavy (internal)--Class and object

Transferred from: http://husbandman.diandian.com/post/2012-08-17/40036035008

Objective-c Sunflower Treasure Book First Heavy (internal) – Classes and objects

Remember: To practice the martial, brandished from the palace, Alchemy medicine, internal and external Qi Tong.

This practice Qi way, but to guide, among insects Taixu, heaven and earth distinguish turbid and stranger, people of practice qi, but practice empty spirit and wash away faint, gas the Lord, shape of the body of the person. Heaven and earth can be reversed, people also have the way of men and women, in this way, must not be lightly transmitted. Cultivation of this work, yourselves yangxin, so that the heart can not afford distractions, detached from the outside of the object, if the mind, not only reactive, but have a life of worry.

Overview

Object

In Objective-c, the underlying data structures of classes and objects can refer to objective-c underlying data structures.

Where objects are implemented through struct objc_object structures

typedef struct OBJC_OBJECT *id;

When the object is running, it produces the form of the structure

We convert this into a more understandable form of data.

The real form of memory is this.

From the object's memory form. The variable members within the object are inherited from the ancestor class (in the father's footsteps), and a copy is generated inside the object. From the memory organization of an object, the object itself is not concerned with behavior (methods of objects or instance methods), with emphasis on the organization of the data.

(_)  _____  ____ _

/ /  / ___/  / __ `/

/ /  (__  )  / /_/ /

/_/  /____/  \__,_/

The NSObject object has an ISA instance variable that inherits from the highest inheritance level. ISA is the key to representing an object. In Objective-c, is not the first class object, ISA is its logo, as if < transformers > Car people have a

If you find the Iron guy is this sign

Then you have to run for your own escape.

ISA is a pointer to the class of the object. Essentially, an instance of the same class points to the same class object (the class is also a special object). The class contains instance methods, which means that all instances of the same class share these instance methods. The message is sent to the object, The object is forwarded to its Isa to point to the class to handle. This phenomenon is similar to the current hot cloud computing.

Cloud chicken A calculate, want wind to Wind, want rain to Rain

The design of objective-c can not only realize object-oriented, but also save memory effectively. Reduce redundant data. The invocation of an object to a method is invoked indirectly through ISA, which causes the dynamic nature of the method invocation, mainly because:

An object does not know whether it can answer a method, which itself does not include the implementation of the method, nor does it contain a pointer to a method, but rather indirectly through the ISA to its own class to know

The instance method in the class is in the form of a chain list, and when run, you can modify the instance method in the list, that is, you can delete and change, which is different from the function in C by default.

From the above analysis, the meaning of ISA is even more significant, if there is no Isa, an object with the Char,int type is no different, there is no ability to respond to the message. So what Isa is, like an ancient official's Wushamao, Wushamao, there is power, Wushamao, is the ordinary

Class

Classes are implemented through struct objc_class structures,

typedef struct OBJC_CLASS *class;

At run time, a structure like this will be generated

In the Objective-c world, one of the first reactions to seeing Isa is, gee, the object. Yes, the class in Objective-c is actually an object.

The world is heartless, with all things as a dog < morals by >

Since the world is born of all things, then what is heaven and earth?

If the human is the ancient goddess Nu wa made, Nagyu and why do they live?

General programming language, at the end of the object is the person who gave birth to himself. The next egg, crawled out of himself. It seems to be rebellious, but it does. NSObject as a root class is such a guy!

This may seem confusing, but for example, hematopoietic stem cells in biology are the manufacturing plants of cells, but who makes hematopoietic stem cells, eh, hematopoietic stem cells

First, the class object is also an object, and it also has its own behavior, which is called a class method. Like the general class instance, the class object does not have the ability to handle the class method, but also to find the class that it belongs to by using Isa, the Meta class, to invoke the class method, The class object itself is also focused on the storage and layout of the data. Classes and meta-classes can be referenced

However, unlike regular class instances, the fields of class objects are generally fixed. That is, it always contains isa,super_class,name,version,info,instance_size,ivars,methodlists,cache by default. Protocols.

The data form of a class would be as follows

and the organization of its data in memory is linear.

We know that in objective-c, our general definition form is to declare an instance variable, a property, an instance method, and a class method of a class. The class variable cannot be declared. Therefore, the data form of the class object is generally the fixed field.

In addition to the ISA that we introduced, the remaining fields have the following meanings:

Super_class Pointer to the parent class. Because Objective-c borrows from Simtalk, it is implemented through an inheritance chain. Super_class is the core field of the entire inheritance chain.

Name of the name class

Version versions

Info Info

Instance_size the memory size of the instance

Ivars is a pointer to the list of instance variables

Methodlists is a pointer to a list of instance methods

Cache caches common instance methods

Protocols is a pointer to a list of protocols

We can simply explain the meaning of the OBJECTIVE-C data structure at runtime.

object is associated with an instance variable, and the object itself stores the instance variable

class objects are related to instance methods, and instance methods must be known through class objects

Meta-classes are related to class methods, and class methods must be known by the meta-class.

objects, classes and meta-classes and Taoism in the three Qing general Oh ~ ~

Classes and objects at run time

Run-time classes and objects such as

Generally speaking

ISA about what class the object is

Super_class About inheritance Chain

All meta-classes have the same meta-class because their Isa points to the same root meta-class

Reference

Objective-c underlying data structure

Classes and meta-classes

    Recommended expand Reading

    Objective-c Sunflower Treasure Book First Heavy (internal)--Class and object

    Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.