Some annoying warnings that still allow the application to work, but would like to remove

I tried the application for testing Bluetooth connectivity. This is a simple application that simply sends a text message from one iDevice to another. Initially, there were about 6 warnings in this application, but I fixed everything but two. They are the same, but deal with different delegates. One for GKPeerPickerControllerDelegate and one for GKSessionDelegate. Let's say the Picker error for a GKPeerPickerController named picker when you enter (a more complete example):

picker.delegate = self; 

the compiler says:

Passing '* const ___ strong' to a parameter of incompatible type 'id'.

For a session named GKSession, enter

 session.delegate = self; 

makes the compiler say:

Sending '* const ___ strong' to a parameter of incompatible type 'id'.

They only appear in the submit button and peerPickerController. I know that these warnings do not interfere with the functions of the application, but I would like to completely update this for Xcode 4.2. This app was originally written for Xcode when iOS 3.0 was new. Yes, I'm a little picky when it comes to writing or practice code, it should not contain any errors / warnings when possible.

These are blocks of code in which a warning occurs:

 -(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 the following:

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

}

+6
source share
2 answers

I believe that any self class cannot accept the formal protocols GKPeerPickerControllerDelegate and GKSessionDelegate . Can you post your interface header?

EDIT

Dropping on id will clear the warnings, but you really haven't “fixed” anything ... looking at the class header, it does not accept the protocols expected by delegates.

Change your interface to accept these protocols:

 @interface BTViewController : UIViewController <GKPeerPickerControllerDelegate, GKSessionDelegate> { 
+5
source

How about session.delegate = (id)self . Maybe you just need to use yourself as an identifier, not const ____.

EDIT: On behalf of the OP, the explanation is in order. A type identifier is required for the protocol, because the protocol itself is literally displayed on the identifier itself ( id<GKSessionDelegate> , etc.). My theory (because I do not use ARC in any of my projects) Is the compiler very demanding, so it can guarantee that your class is safe to issue. You probably initialized your class in a non-id way. Of course, I have no idea how, if anyone knows; I would be happy to let them edit this answer.

EDIT 2: as Teddy said, accepting protocols in your header file also blocks this warning. I apologize for thinking it meant you accepted the protocols.

+3
source

Source: https://habr.com/ru/post/905132/


All Articles