The usage of @class in objective-c

Source: Internet
Author: User

1, @class: declaration is a class
When we actually use the class, import the class using import

2, the following code will be an error, because import can not reference each other, this is just a @class declaration class can
#import "B.h"
@interface A:nsobject

@end

#import "A.h"
@interfact B:nsobject

@end

3, if you are inheriting a class, you should import the header file of the class,
If you are simply defining member variables, attributes, and using the @class

4. There are two ways to introduce classes
#import: Contains all the information about a class, including variables, methods, which can degrade the performance of the compilation
@class: Just tell the compiler that this is a class that declares a class.

5, @class only need to know the name of the referenced class can be. In the implementation class, because you want to use the entity variables and methods in the referenced class, all of the. m files need to use #import to contain the header file of the referenced class.
If hundreds of headers are #import the same file, or if the files are #import at once, all classes that are referenced to this file will need to be changed once the first file is burned.

6. For dependencies, for example, a class-dependent b,b relies on a #import就会报编译错误

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.