Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 641
David L Avatar asked Mar 25 '12 15:03

David L


4 Answers

At this line :

gameAddViewContoller.delegate=self; 

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

like image 200
giorashc Avatar answered Oct 14 '22 06:10

giorashc


For me what ended up happening is that I wasn't adding the delegate to the @interface on my header file

For example

@interface TheNameOfYourClass : UIViewController <TheDelegatorClassDelegate>

@end
like image 29
Raul Lopez Avatar answered Oct 14 '22 06:10

Raul Lopez


You are putting the < GameAddViewControllerDelegate > in the wrong place. It doesn't go on GameAddViewController, it goes on ViewController.

like image 14
borrrden Avatar answered Oct 14 '22 05:10

borrrden


This might help other people who are adding Multipeer Connectivity straight to a ViewController. At the top of myViewControllerName.h add '<MCSessionDelegate>':

@interface myViewControllerName : UIViewController<MCSessionDelegate>
like image 4
Custom Bonbons Avatar answered Oct 14 '22 06:10

Custom Bonbons