I'm following a tutorial written in objective-c here and I've converted most things to swift already, however some lines just won't work.
for example, I've converted the following structs:
typedef struct { MessageType messageType; } Message; typedef struct { Message message; } MessageMove; to this:
struct Message { var messageType:MessageType } struct MessageMove { var message:Message } and in another line, the tutorial does the following:
- (void)match:(GKMatch *)match didReceiveData:(NSData *)data fromPlayer:(NSString *)playerID { Message *message = (Message*)[data bytes]; if (message->messageType == kMessageTypeMove) { MessageMove *messageMove = (MessageMove*) [data bytes]; } } I've tried changing this to the following:
func matchDidReceiveDataFromPlayer(match: GKMatch, data: NSData, player: GKPlayer) { //1 var message = data.bytes as Message //DOESNT WORK if (message.messageType == MessageType.kMessageTypeGameBegin) //2 var messageMove = data.bytes as MessageMove //WORKS } but the first cast (//1) doesn't work, it says the following:
UnsafePointer<Void> not convertible to Message
however the second cast (//2) works. Is it because I'm doing a check on the message type in the if statement?
any ideas on how to fix this?