IOS review notes 12: categories, ios review notes 12

Source: Internet
Author: User

IOS review notes 12: categories, ios review notes 12

1. Function Description
1.1 add methods to existing classes. member variables cannot be added.
1.2 place the implementation of classes in different files
1.3 create a reference to a private Method
2 format
Header file (file name: "class name + class name. h ")
# Import "class name. h"
@ Interface Class Name (category name)
// Declaration of the new method
@ End


Source file (file name: "class name + class name. m ")
# Import "class name + class name. h"
@ Interface Class Name (category name)
// New Implementation Method
@ End


3 Examples
Assume that there is a Person class, as shown below:

// Person. h # import <Foundation/Foundation. h> @ interface Person: NSObject @ end


// Person. m
# Import "Person. h" @ implementation Person @ end



Now we want to add an eat and run method to the Person class:


// Person + action. h
# Import "Person. h" @ interface Person (action)-(void) eat;-(void) run; @ end


// Person + action. m
# Import "Person + action. h" @ implementation Person (action)-(void) eat {}- (void) run {}



In this way, the Person class has the eat and run methods, and all of them can call two methods.

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.