Rid*_*wan 30 iphone objective-c
每当我构建以下代码时,我都会收到上面的错误.
//Controller.h
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
#import "PolygonShape.h"
#import "PolygonView.h";
@interface Controller : NSObject
{
IBOutlet UIButton *decreaseButton;
IBOutlet UIButton *increaseButton;
IBOutlet UILabel *numberOfSidesLabel;
IBOutlet PolygonShape *shape;
IBOutlet PolygonView *shapeView;
}
- (IBAction)decrease;
- (IBAction)increase;
- (void)awakeFromNib;
@end
//Controller.m
#import "Controller.h"
@implementation Controller
@end
Run Code Online (Sandbox Code Playgroud)
但是,当我替换import语句并改为使用前向类引用时,代码将编译.
//Controller.h
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
#import "PolygonShape.h"
@class PolygonView;
@interface Controller : NSObject
{
IBOutlet UIButton *decreaseButton;
IBOutlet UIButton *increaseButton;
IBOutlet UILabel *numberOfSidesLabel;
IBOutlet PolygonShape *shape;
IBOutlet PolygonView *shapeView;
}
- (IBAction)decrease;
- (IBAction)increase;
- (void)awakeFromNib;
@end
//Controller.m
#import "Controller.h"
#import "PolygonView.h"
@implementation Controller
@end
Run Code Online (Sandbox Code Playgroud)
谁能解释一下?
Chr*_*sJF 25
是的,我也有这个循环依赖的问题,我在彼此导入这两个类.我也不知道前进宣言是什么.我在维基百科上及时搜索了它,但描述得很糟糕.我发现这篇文章解释了它们是什么以及它们与周期性进口的关系.http://timburrell.net/blog/2008-11-23/effective-c-cyclical-dependencies/
注意:链接不断下降所以我只是PDF了.
我有一个简单的错误得到了这个错误......也许其他人也这样做了?
正确:
@interface ButtonDevice : NSObject
{
NSString *name;
NSString *uri;
NSString *icon;
}
@property (nonatomic, retain) IBOutlet NSString *name;
@property (nonatomic, retain) IBOutlet NSString *uri;
@property (nonatomic, retain) IBOutlet NSString *icon;
@end
Run Code Online (Sandbox Code Playgroud)
错误:
@interface ButtonDevice : NSObject
{
NSString *name;
NSString *uri;
NSString *icon;
@property (nonatomic, retain) IBOutlet NSString *name;
@property (nonatomic, retain) IBOutlet NSString *uri;
@property (nonatomic, retain) IBOutlet NSString *icon;
}
@end
Run Code Online (Sandbox Code Playgroud)
只需遵循此规则即可避免此类问题:
如果对象仅由类的实现文件在内部使用,则在头文件中使用 forward声明并在实现文件中导入/ include.否则在标题中使用 import.
| 归档时间: |
|
| 查看次数: |
50536 次 |
| 最近记录: |