Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ViewController type name not recognized in one class, but it is in another?

I am getting a build semantic error in XCode when I attempt to build my project. I have 3 NSOperation classes setup to download information from the internet, process it, and send it to the parent view controller, an instance of ViewController. Here is the code for a working class:

#import <Foundation/Foundation.h>
#import "ViewController.h"

@interface ImageGetter : NSOperation

@property (nonatomic) int sid;
@property (nonatomic, retain) ViewController* pvc;

@end

Here is the code for the one that is not working:

#import <Foundation/Foundation.h>
#import "ViewController.h"

@interface CurrentGetter : NSOperation

@property (nonatomic) int sid;
@property (nonatomic, retain) ViewController* pvc;

@end

Error:

ERROR: Unknown type name 'ViewController'; did you mean 'UIViewController'?

Why am I getting this error? I imported ViewController.h in both files and only one is working.

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
like image 404
Liftoff Avatar asked Mar 04 '13 16:03

Liftoff


1 Answers

Try doing a forward declaration of the class in your CurrentGetter header file, like this:

@class ViewController;
@interface CurrentGetter : NSOperation

This tells the compiler that there exists a class called "ViewController." When there are circular dependencies, like when two classes have instances of each other, using forward declarations of the classes resolves the confusion that results.

like image 89
ewrobinson Avatar answered Nov 14 '22 23:11

ewrobinson