在Objective-C我用下面的代码来如何在Swift中将Int转换为NSData?
转换一个
Int
可变进NSData
,字节的分组。int myScore = 0; NSData *packet = [NSData dataWithBytes:&myScore length:sizeof(myScore)];
使用转换
NSData
可变成的方法。[match sendDataToAllPlayers: packet withDataMode: GKMatchSendDataUnreliable error: &error];
我试图Objective-C的码转换为夫特:
var myScore : Int = 0
func sendDataToAllPlayers(packet: Int!,
withDataMode mode: GKMatchSendDataMode,
error: NSErrorPointer) -> Bool {
return true
}
然而,我无法一个Int
变量转换成NSData
和使用它的方法。我怎样才能做到这一点?
http://stackoverflow.com/a/28662828/2303865 – 2015-02-23 19:02:34