根据我的理解,如果ClassA需要包含ClassB头,则应该使用前向声明,而ClassB需要包含ClassA头以避免任何循环包含.我也明白a #import是一个简单的,ifndef所以包含只发生一次.
我的询问是这样的:什么时候使用#import,什么时候使用@class?有时如果我使用@class声明,我会看到一个常见的编译器警告,如下所示:
warning: receiver 'FooController' is a forward class and corresponding @interface may not exist.
真的很想理解这一点,而不是仅仅删除@class前向声明并抛出一个#import静音编译器给我的警告.
我在我身上遇到两个问题,我FooterSelectorView.h不明白为什么.一个是警告而另一个是错误.由于某些原因,xcode无法识别,FooterArchiveItemView因此我无法将对象键入为导致其他问题的对象.有没有人见过这样的事情呢?我该如何解决?
FooterSelectorView.h
#import <UIKit/UIKit.h>
#import "FooterArchiveItemView.h"
@interface FooterSelectorView : UIImageView
// #warning Type of property 'activeItem' does not match type of accessor 'setActiveItem:'
@property (nonatomic, retain) FooterArchiveItemView *activeItem;
// #error Expected a type
- (void)setActiveItem:(FooterArchiveItemView *)activeItem_;
- (void)update;
- (CGPoint)absoluteCenterOf:(UIView *)obj;
@end
Run Code Online (Sandbox Code Playgroud)
相关课程
FooterArchiveItemView.h
#import <UIKit/UIKit.h>
#import "AutosizeableView.h"
#import "FooterArchiveView.h"
typedef void (^ DayBlock)(void);
@interface FooterArchiveItemView : AutosizeableView {
DayBlock dayBlock;
}
@property (nonatomic, retain) IBOutlet UIButton *day;
@property (nonatomic, retain) IBOutlet UIImageView *bullet;
- (void)setDayBlock:(DayBlock)block; …Run Code Online (Sandbox Code Playgroud)