Question

I tried out an app to test bluetooth communication. It is a simple app that just sends a message in text form from one iDevice to another. Originally, this app had about 6 warnings but I fixed all but two. They are the same but deal with different delegates. One is for the GKPeerPickerControllerDelegate and the other for the GKSessionDelegate. Say the Picker error is for the GKPeerPickerController named picker, when you type (more complete example to follow):

picker.delegate = self;

the compiler says:

Passing '*const___strong' to parameter of incompatible type 'id'.

For the GKSession named session, typing

session.delegate = self;

makes the compiler say:

Sending '*const___strong' to parameter of incompatible type 'id'.

These only pop in the button to send and peerPickerController. I know that these warnings do not impede on the app's ability to function but I would like to completely update this for Xcode 4.2. This app was originally written for Xcode back when iOS 3.0 was new. Yes, I am a bit picky when it comes to writing or practicing code, it must not contain any errors/warnings whenever possible.

These are the code blocks where the warning occur:

-(IBAction)btnConnect:(id)sender{
    picker = [[GKPeerPickerController alloc] init];
    picker.delegate = self;  //Warning here
    picker.connectionTypesMask = GKPeerPickerConnectionTypeNearby;

    [connect setHidden:YES];
    [disconnect setHidden:NO];
    [picker show];
}

-(void)peerPickerController:(GKPeerPickerController *)PCpicker didConnectPeer:(NSString *)peerID toSession:(GKSession *)session{
    self.currentSession = session;
    session.delegate = self;  //Warning here
    [session setDataReceiveHandler:self withContext:nil];
    PCpicker.delegate = nil;

    [PCpicker dismiss];
}

Edit:

The header has this:

    @interface BTViewController : UIViewController{
GKSession *currentSession;
IBOutlet UITextField *txtMessage;
IBOutlet UIButton *connect;
IBOutlet UIButton *disconnect;

GKPeerPickerController *picker;

}

Was it helpful?

Solution

I believe whatever class self is may not be adopting the GKPeerPickerControllerDelegate and GKSessionDelegate formal protocols. Can you post your interface header?

EDIT

Casting to id will clear the warnings, but you really didn't "fix" anything...looking at the class header, it is not adopting the protocols that the delegates are expecting.

Modify your interface to adopt those protocols:

@interface BTViewController : UIViewController <GKPeerPickerControllerDelegate, GKSessionDelegate> {

OTHER TIPS

What about session.delegate = (id)self. Maybe you just need to cast self as ID instead of const____strong.

EDIT: At the bequest of the OP, an explanation is in order. Type id is necessary for the protocol, because the protocol itself is literally typecast to id itself (id<GKSessionDelegate> etc.). My theory (because I am not using ARC in any of my projects) Is that the compiler gets very exacting so it can guarantee that your class is safe for release. You probably initialized your class in a non-id way... Of course I have no idea how, if anyone knows; I'd be happy to let them edit this answer.

EDIT 2: as Teddy said, adopting the protocols in your header file also silences this warning. I apologize for thinking it was implied that you had adopted the protocols.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top