Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pack struct in NSData? [duplicate]

Possible Duplicate:
Send and receive NSData via GameKit

I have struct which consists of int variable and 2 float pointers (arrays). How can I pack this struct ib NSData and later unpack it?

like image 751
Mathemage Avatar asked Sep 08 '12 06:09

Mathemage


Video Answer


1 Answers

You can pack the structure using dataWithBytes method pf NSData :

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)];
like image 175
aleroot Avatar answered Oct 08 '22 01:10

aleroot