gpt4 book ai didi

iphone - 结构到 NSData 到结构?

转载 作者:太空狗 更新时间:2023-10-30 03:12:47 24 4
gpt4 key购买 nike

我有以下结构:

typedef enum
{
kPacketTypeJoin = 1,
kPacketTypeServerAcceptedJoin,
kPacketTypeSelectedNumber,
} PacketTypes;
typedef struct
{
PacketTypes type;
NSString *name;
} PacketJoin;

我如何将 PacketJoin 转换为 NSData 并再次返回到 PacketJoin?

最佳答案

// make a NSData object
NSData *myData = [NSData dataWithBytes:&myPacketJoin length:sizeof(myPacketJoin)];

// make a new PacketJoin
PacketJoin newJoin;
[myData getBytes:&newJoin length:sizeof(newJoin)];

关于iphone - 结构到 NSData 到结构?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5373545/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com