Objective-c (Syntax II)

Source: Internet
Author: User
Tags print object

category: You can extend some methods to a class (without modifying the code of the original class)

function : You can add some methods to the class without changing the original class content.

Use note :

1. Only add methods, cannot increase member variables

2. member variables in the original class can be accessed in the classification method implementation

3. Classification can be re-implemented in the original class method, overwriting the original class method, resulting in the original class method can no longer be used

4. Classification of the highest priority: Call a method first to the classification to find, then go to the original class, and then find the parent class

Classification (last compiled precedence)-"original Class-" Parent class

Statement:

@interface class names (category name)

@end

Realize:

@implementation class Name

@end

the nature of the class :

The class itself is also an object, a class-type object, or a class object

Definition of class type

typedef struct OBJC Class *class

The class name represents the class object, with only one class object per class

+load methods and +initialize methods:

1. When the program starts, all classes and classifications in the project are loaded, and the +load method for each class and classification is called after it is loaded. will only be called once.

2. When a class is used for the first time, the +initialize method of the current class is called, and a class invokes only one +initialize method

3. Load the parent class first, then load the subclass (call the +load method of the parent class first, and then call the +load method of the subclass)

Initializes the parent class first, initializes the subclass (calls the +initialize method of the parent class, and then calls the +initialize method of the subclass.

Description method

Modify the default output when using NSLog output properties, overriding the +description method or-desription method

+description Method:

By default, when you use the NSLog and%@ output objects, the-desription method of the calling object, the return value (NSString *) screen output is the:< class name: Memory address >

+desription Method:

By default, when you use the NSLog and%@ output class objects, you call the +desription method of the class object and get the return value (NSString *) of the screen output

Note the point:

Do not attempt to use self in the-desription method, resulting in a dead loop

NSLog Printing

1. %p

Print the address of the pointer variable p

NSLog (@ "%p", &p);

Print Object Address

NSLog (@ "%p", p);

2. %@

%@ Print < Class Name: Object address >

NSLog (@ "%@", p);

3. _line_ %d output Current line number

4. _file_ %s output file path

5. _func_ %s output Current function

SEL

Full name Selector

The SEL is actually a wrapper for the method, wrapping the method into an SEL type of data, finding the corresponding method address, and finding the method address to invoke the method

_cmd represents the current method

The message is sel.

Objective-c (Syntax II)

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.