Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

A bit of annoying warnings that still let the app work but would like to remove

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;

}

like image 876
mike_r Avatar asked Jan 04 '12 19:01

mike_r


People also ask

How do I stop notifications from popping up on my screen?

On Android phones, swipe down from the top of the screen to access your notification shade and tap the Do Not Disturb icon. Go to Settings > Sound > Do Not Disturb to set exceptions and more. Use an older iPhone or iPad?

How do I get rid of annoying app notifications?

Go to your Phone Settings. Open Apps & Notifications. Tap on Notifications. It shows you the apps for the most recent/frequently sent notifications, you can turn any of them as per your choice.

How do I get notifications to go away on an app?

First, press-and-hold on the persistent notification you want to remove. Another option is to swipe the notification left or right, and then tap on the cogwheel icon shown next to it. Next, tap on the switch next to Permanent to disable it, and then press Save.


2 Answers

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> {
like image 67
Tim Reddy Avatar answered Sep 28 '22 08:09

Tim Reddy


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.

like image 37
CodaFi Avatar answered Sep 28 '22 08:09

CodaFi