Reputation: 3
I'm retrieving a unix timestamp from a Bluetooth LE peripheral, which is stored in an NSData object. If I print the contents of the NSData object to the debug console, they appear correct, however if I try to convert the NSData object to an integer value, the integer value appears to keep changing.
NSData *refinedData = [mfrData subdataWithRange:range];
Which yields a value of 386d5e9a on the debug console.
I then convert to an integer:
uint32_t unixTimeStamp = refinedData;
Initially, this yields a value of 342162144 on the debug console. However, this value keeps growing, despite the NSData not changing. Can anybody help me understand what's going on?
If it's not already very apparent, I'm a newbie.
Thanks.
Upvotes: 0
Views: 133
Reputation: 21383
refinedData
is a pointer to an instance of NSData. You want to access its contents:
uint32_t unixTimeStamp = *(uint32_t *)[refinedData bytes];
Note that this is simplified, and assumes that the bytes returned by the Bluetooth peripheral are the same endianness as the processor in your device, that range
is correct, etc.
Upvotes: 1