title: Sending and receive NSMutableArray as Bytes using GameKit
body: <p>I am trying to send an Array from one player to another.</p>
  
  <p>I create a struct in the header</p>
  
  <pre><code>typedef struct {
      Message message;
      unsigned int numBytes;
      void * bytes;
  } MessagePingBackToCaller;
  
  typedef struct {
      MessageType messageType;
  } Message;
  </code></pre>
  
  <p>And try to send with this:</p>
  
  <pre><code>-(void)sendOpponentRadar{
  
      MessagePingBackToCaller sendMessage;
      sendMessage.message.messageType = kMessageTypeRecievedRadarPing;
      NSData *pingData = [NSKeyedArchiver archivedDataWithRootObject:[cover gatherAndReturnColumnNumbers]];
  
      sendMessage.bytes = pingData;
  
      NSData *data = [NSData dataWithBytes:&amp;sendMessage length:sizeof(MessagePingBackToCaller)];    
      [self sendData:data];
  }
  </code></pre>
  
  <p>And receive with this:</p>
  
  <pre><code>if (message-&gt;messageType == kMessageTypeRecievedRadarPing){
  
          MessagePingBackToCaller *messageSent = (MessagePingBackToCaller *)[data bytes];
  
          NSLog(@"Data : %@", messageSent-&gt;bytes);
  
          NSMutableArray *array = [NSKeyedUnarchiver unarchiveObjectWithData:messageSent-&gt;bytes];
          NSLog(@"Results : %@", array);
      }
  </code></pre>
  
  <p>However no luck, so I went looking around and found that @rwenderlich wrote a little helpful bit:</p>
  
  <ol>
  <li><p>Convert NSArray to NSData</p></li>
  <li><p>In struct, store an unsigned int numBytes, and a void * bytes</p></li>
  <li><p>In numBytes, write the length of the NSData, and then write out the contents of the NSData</p></li>
  <li><p>On the other side, read numBytes to see how many bytes to read next, then read in that amount of bytes and reverse the process (bytes->NSData->NSArray).</p></li>
  </ol>
  
  <p>Im pretty good on 1 and 2... I believe, but i get lost on 3 and 4. Could someone please help me translate this into meaningful code?</p>
  
  <p>Thanks!</p>