I am creating a game that sends some data between devices in multiplayer game centre.
The data I'm sending includes an NSArray & a message to notify the other player of a change in the score.
I have defined the struct for the score message as such:
typedef NS_ENUM(NSUInteger, MessageType) {
kMessageTypeUpdateScore
};
typedef struct {
MessageType messageType;
} Message;
typedef struct {
Message message;
int score;
} MessageUpdateScore;
And here's the code for receiving the data:
- (void)match:(GKMatch *)match didReceiveData:(NSData *)data fromPlayer:(NSString *)playerID {
NSArray *array = [NSKeyedUnarchiver unarchiveObjectWithData:data];
// data is an array
Message *message = (Message *)[data bytes];
if (message->messageType == kMessageTypeUpdateScore) {
// data is a message
}
}
My question is - how do I differentiate between the NSArray & Message such that I can unpack the NSData and do different things with it accordingly?