I'm communicating over the network using c style structs. This is working for ints & the like as I'm passing the real value. I can't figure out how to pass a string over.
I have tried variations of
Code:
typedef struct {
Message message;
uint32_t cost;
const char *costName;
} MessageCost;
I have only been able to declare this as a pointer, which obviously won't work on the other end.
the receiver then has:
Code:
else if (message->messageType == kMessageTypeCost) {
MessageCost *messageCost = (MessageCost *) [data bytes];
NSLog(@"Received: %@", messageCost->costName);
I'm getting a bad access getting the cost name as it's a pointer to memory that isn't valid on this device.
I'm creating the string:
Code:
message.costName = [name UTF8String];
(name is just a NSString)
so this will work fine if I'm passing the string within the same device where the memory is valid but how do I do this between devices?
thanks!