可能的重复:
通过 GameKit 发送和接收 NSData https://stackoverflow.com/questions/4837102/send-and-receive-nsdata-via-gamekit
我有一个由 int 变量和 2 个浮点指针(数组)组成的结构。如何打包这个结构 ib NSData 然后再解压它?
您可以使用 NSData 的 dataWithBytes 方法打包结构:
struct aStruct {
/* Implementation */
};
//Struct variable
aStruct exampleStruct;
// pack the struct into an NSData Object
NSData *myData = [NSData dataWithBytes:&exampleStruct length:sizeof(exampleStruct)];
// get back the the struct from the object
[myData getBytes:&exampleStruct length:sizeof(exampleStruct)];
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)