Assigning to 'id<Delegate>' from incompatible type 'ViewController *const_strong'

David L picture David L · Mar 25, 2012 · Viewed 90.5k times · Source

Throughout my app, I'm getting semantic issue warnings when I set ViewController.delegate = self. I have searched and found similar posts but none were able to solve my problem.

ViewController.m:

GameAddViewController *gameAddViewContoller = [[navigationController viewControllers] objectAtIndex:0];
gameAddViewContoller.delegate=self;

I get the error message when setting .delegate=self.

GameAddViewController.h:

@protocol GameAddViewControllerDelegate <NSObject>

- (void)gameAddViewControllerDidCancel:(GameAddViewController *)controller;
- (void)gameAddViewController:(GameAddViewController *)controller didAddGame:(Game *) game;

@end

@interface GameAddViewController : UITableViewController <GameAddViewControllerDelegate>
{
sqlite3         *pitchcountDB;
NSString        *dbPath;
}
@property (nonatomic, strong) id <GameAddViewControllerDelegate> delegate;
...
@end

ViewController.h:

#import "GameAddViewController.h"

@class ViewController;
@protocol ViewControllerDelegate <NSObject>
- (void)ViewControllerDidCancel:(ViewController *)controller;

@end
@interface ViewController : UIViewController <ViewControllerDelegate>
-(void) checkAndCreateFile;
@end

Can anyone point me in the right direction to resolve the warning messages?

Answer

giorashc picture giorashc · Mar 25, 2012

At this line :

gameAddViewContoller.delegate=self; 

Notice that self is of type ViewController which does NOT conform to the GameAddViewController protocol.