I'm sort of rewriting application from this link: http://www.raywenderlich.com/12910/how-to-make-a-simple-playing-card-game-with-multiplayer-and-bluetooth-part-3
and I'm stuck with NSData
and stuff that has to do with bytes
!
What type does 0x64 represents here?
typedef enum
{
PacketTypeSignInRequest = 0x64, // server to client
PacketTypeSignInResponse, // client to server
...
}
PacketType;
Which type should my enum be in swift?
Main problems I encountered are here:
- (void)rw_appendInt32:(int)value
{
value = htonl(value);
[self appendBytes:&value length:4];
}
- (void)rw_appendInt16:(short)value
{
value = htons(value);
[self appendBytes:&value length:2];
}
- (void)rw_appendInt8:(char)value
{
[self appendBytes:&value length:1];
}
- (void)rw_appendString:(NSString *)string
{
const char *cString = [string UTF8String];
[self appendBytes:cString length:strlen(cString) + 1];
}
I have no idea how should be this written in NSData
extension.
Last but not least, how do I pass this 'SNAP' in swift since characters are written almost the same as string in swift?
[data rw_appendInt32:'SNAP']; // 0x534E4150
[data rw_appendInt32:0];
[data rw_appendInt16:self.packetType];
Also if anyone have any good link on this kind of stuff that has to do with data, int's of different sizes (doesnt have to be swift/objc) please send!