<分区>
我最近看了一个教程,演讲者说如果你使用它没有什么区别:
#import "Class.h"
或:
@class Class;
而且我不得不说,我的应用程序以一种或另一种方式工作。 但一定有区别吧?所以我想问问你们。
提前致谢!
<分区>
我最近看了一个教程,演讲者说如果你使用它没有什么区别:
#import "Class.h"
或:
@class Class;
而且我不得不说,我的应用程序以一种或另一种方式工作。 但一定有区别吧?所以我想问问你们。
提前致谢!
最佳答案
根据 Apple 文档:
@class allows you to declare that a symbol is an Objective-c class name without the need to #import the header file that defines the class.
You would use this where you only need the class name defined for the purposes of declaring a pointer to the class or a method parameter of the class, and you do not need to access any methods, fields, or properties in the class.
It saves a minuscule amount of compile time vs the #import, and it sometimes helps avoid messy include circularity issues.
来自 here 的好答案
例如当你创建一个协议(protocol)时:
@class yourCustomView;
@protocol yourCustomViewDelegate <NSObject>
@required
- (void) somethingDidInView:(UIView*)view;
@end
@interface yourCustomView : FIView
关于ios - #import 和@class 之间的区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19465059/