Object-c extension of the language class

Source: Internet
Author: User

First, Category      1, Category: Also called classification, category. is for classes that do not have source code to extend functionality.     The expanded functionality becomes part of the original class and can be called directly from the original class or the original object, and can be inherited.          2, Note: 1) This method can only expand the methods, can not expand the instance variable, @property (May compile without error, but run a problem).          2) Categories can access members in the original class.          3) If the classification and the original class have a method with the same name, the method in the classification is prioritized, and the methods in the original class are ignored. 4) When you have a method with the same name in multiple classes, you are executing the method with the same name as the last compiled class. Second, Extension      1. Add private instance variables and methods to the class that can get the source code.     2. Note: The class that extends the operation must be a class that can get the source code (a class with a. m file). 3, category and extension difference 1) Different functions: category is the function of the extended class, extension is used to declare private methods and instance variables of the Class 2) category stored in a bunch of. h. m files, Exten Sion stored in. m files 3) extension can add instance variables, category can not three, delegate design mode      1, the use of delegate design mode we need to understand the first three elements-the principal, the agent, the agreement.          1) Principal: The person (object) who entrusts others to perform certain operations.          2) Protocol (PROTOCOL): The client needs the action performed by the agent.     3) Agent: The person (object) that is entrusted to perform certain operations. 2, the agreement is a set of standards (a bunch of methods of declaration), only. h files. The definition of the agreement begins with @protocol and ends with @end.      For example: declaring a marriage agreement. @protocol Marryprotocol <NSObject>
@required
-(void) Makemoney; Money
@optional
-(void) cooking; Cook

@end 3, 1) Step 1: The client formulates a set of agreements (in the. h file of the principal party), which declares the method that the principal needs to be executed by the agent (only the method declaration).          2) Step 2: The principal declares a delegate property (assign adornment) that stores the proxy object.          3) Step 3: The agent is required to comply with the agreement and implement the methods in the Protocol.          4) Step 4: Set the agent as the delegate's agent (the proxy object is assigned to the delegate property of the delegate object, and is stored).           5) Step 5: The client notifies the proxy object at the appropriate time to perform the appropriate action. Note: Respondstoselector: This method determines whether an object can respond to a selected method.

Object-c extension of the language class

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.