IOS Run-time mechanism

Source: Internet
Author: User

One, the OBJECTIVE-C runtime defines several important types.

    • Class: Defining the Objective-c Class
    • Ivar: Defines an instance variable of an object, including the type and name.
    • Protocol: Define formal agreements.
    • objc_property_t: Defines a property. This name may be called to prevent conflicts with user types in Objective-c 1.0, when there are no attributes.
    • Method: Defines an object method or class method. This type provides the name of the method (that is, the * * selector), the number and type of parameters, and the return value (which together is called the * * Signature of the method), and a function pointer to the code (that is, the method's implementation * *).
    • SEL: Defines the selector. The selector is a unique identifier for the method name.
    • IMP: Defines the method implementation. This is just a pointer to a function that takes an object, a selector, and a variable-length argument list (varargs), returning an object

Second, the difference between class_copypropertylist and Class_copyivarlist

Class_copypropertylist:

Gets the class's property variables through the class name.

Class_copyivarlist

Gets the instance variable of the class through the class name.

Other words:

Class_copypropertylist obtained is a variable modified by @property,

Class_copyivarlist obtained is class_copypropertylist modified and in the M file in the @implementation defined within the variable

eg

. h

@interface Model:nsobject

@property (nonatomic,copy) NSString *sex;

@property (nonatomic,copy) NSString *name;

@property (nonatomic,assign) Nsinteger age;

@property (Nonatomic,strong) nsdictionary *imgcode;

@end

. m

@interface Model ()

@property (nonatomic,copy) NSString *id;

@end

@implementation Model {

Nsinteger _index;

}

@end

When using the

unsigned int propertiescount = 0;

unsigned int ivarscount = 0;

objc_property_t *properties = class_copypropertylist (Model, &propertiescount);

Ivar *ivars = class_copyivarlist (Model, &ivarscount);

Then Propertiescount = 5

Ivarscount = 6

IOS Run-time mechanism

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.