当我尝试构建项目时,我在XCode中遇到了构建语义错误。我有3个NSOperation
类设置来从互联网上下载信息,处理它,并将其发送到父视图控制器,ViewController
的实例。以下是工人阶级的代码:
#import <Foundation/Foundation.h>
#import "ViewController.h"
@interface ImageGetter : NSOperation
@property (nonatomic) int sid;
@property (nonatomic, retain) ViewController* pvc;
@end
以下是不工作的代码:
#import <Foundation/Foundation.h>
#import "ViewController.h"
@interface CurrentGetter : NSOperation
@property (nonatomic) int sid;
@property (nonatomic, retain) ViewController* pvc;
@end
错误:
ERROR: Unknown type name 'ViewController'; did you mean 'UIViewController'?
为什么我收到此错误?我在两个文件中导入了ViewController.h,只有一个正在工作。
ViewController.h:
#import <UIKit/UIKit.h>
#import <AVFoundation/AVFoundation.h>
#import <MediaPlayer/MediaPlayer.h>
#import "DataGetter.h"
#import "CurrentGetter.h"
#import "AppDelegate.h"
@interface ViewController : UIViewController <UITabBarDelegate>
{
NSTimer* tmr;
}
@property (nonatomic) float max;
@property (nonatomic, retain) NSDictionary* plist;
@property (nonatomic, retain) NSArray* processingobj;
@property (nonatomic, retain) AVAudioPlayer* intro;
@property (nonatomic, retain) AVAudioPlayer* woop;
@property (nonatomic) float dataDone;
@property (nonatomic) BOOL introDone;
@property (nonatomic) BOOL currentDone;
@property (nonatomic) int newSid;
@property (nonatomic) int newPart;
@property (nonatomic, retain) NSMutableArray* views;
@property (nonatomic) int audioTab;
@property (nonatomic) int currentSid;
@property (nonatomic) BOOL isPlaying;
@property (nonatomic, retain) UIScrollView* partTab;
@property (nonatomic, retain) NSMutableArray* nowPlayingObj;
@property (nonatomic, retain) UINavigationBar* audioNav;
@property (nonatomic, retain) MPMoviePlayerController* player;
@property (nonatomic, retain) UILabel* elapsed;
@property (nonatomic, retain) UILabel* remaining;
@property (nonatomic, retain) UISlider* slider;
@property (nonatomic) BOOL sliderEditing;
@property (nonatomic, retain) UIButton* playBtn;
@property (nonatomic, retain) UITabBar* tabBar;
//Images
@property (nonatomic, retain) UIImage* announcement;
@property (nonatomic, retain) NSMutableArray* seriesBanners;
@property (nonatomic, retain) UIProgressView* prog;
- (void)plistDone;
@end
答案 0 :(得分:12)
尝试在CurrentGetter头文件中进行类的前向声明,如下所示:
@class ViewController;
@interface CurrentGetter : NSOperation
这告诉编译器存在一个名为“ViewController”的类。当存在循环依赖时,例如当两个类具有彼此的实例时,使用类的前向声明可以解决导致的混淆。