CopyWithZone-unrecognized selector sent to instance

I use the following code to instantiate the SenderPlayerViewController and pass the session object:

- (void)session:(GKSession *)session peer:(NSString *)peerID didChangeState: GKPeerConnectionState)state { switch (state) { case GKPeerStateConnected: NSLog(@"Connected Central"); if ([settings.playerType isEqualToString:@"SENDER"]){ SenderPlayerViewController *myViewController = [[UIStoryboard storyboardWithName:@"MainStoryboard" bundle:NULL] instantiateViewControllerWithIdentifier:@"SenderPlayerViewController"]; [self.navigationController pushViewController:myViewController animated:YES]; myViewController.currentSession=session; } break; case GKPeerStateDisconnected: NSLog(@"Disconnected Central"); self.currentSession = nil; break; } } 

SenderPlayerViewController view header file:

 @interface CentralViewController : UIViewController { Settings *settings;} @property (nonatomic, copy) GKSession *currentSession; @end 

When the code is executed, I get the following error:

 [GKSession copyWithZone:]: unrecognized selector sent to instance 0x9661200 

need more help here ....

+7
source share
2 answers

Property:

 @property (nonatomic, copy) GKSession *currentSession; 

wrong. GKSession is not an object to copy. Therefore, you should just get a link to it, saving:

 @property (nonatomic, retain) GKSession *currentSession; 
+7
source

Your Custome Class GKSession should be a subclass of NSObject, and you better implement the method declared in the NSCopy protocol

0
source

All Articles