How to convert an Int into NSData in Swift?
问题 In Objective-C I use the following code to Convert an Int variable into NSData , a packet of bytes. int myScore = 0; NSData *packet = [NSData dataWithBytes:&myScore length:sizeof(myScore)]; Use the converted NSData variable into a method. [match sendDataToAllPlayers: packet withDataMode: GKMatchSendDataUnreliable error: &error]; I tried converting the Objective-C code into Swift: var myScore : Int = 0 func sendDataToAllPlayers(packet: Int!, withDataMode mode: GKMatchSendDataMode, error: