1

I'm working on a project where I get a log back from an BLE device.

<37290000 00000000 0000>

This log contains the epochtime, a light value and a UV value. Now is my question, what is the best way to split this up?

I use the following code to get the above print:

print(data as NSData)
Riyan Fransen
  • 534
  • 1
  • 3
  • 14
  • Possible duplicate of [Swift: Split a String into an array](https://stackoverflow.com/questions/25678373/swift-split-a-string-into-an-array) – Tamás Sengel Nov 07 '17 at 13:00
  • Can you show the code where you are creating the log statement? Maybe you shouldn't be trying to get your values out of the log statement, but out of the original data. – Marcel Nov 07 '17 at 13:10
  • @Marcel I updated the quesstion. – Riyan Fransen Nov 07 '17 at 13:20
  • Do you want to split `bytes` or `Data`, or to do something with String `description` of `NSData`? – user28434'mstep Nov 07 '17 at 13:22
  • 1
    Maybe using a struct https://stackoverflow.com/questions/28916535/swift-structs-to-nsdata-and-back ? – Larme Nov 07 '17 at 13:23
  • @user28434 I want to split the Data, I have the rest of the code ready to continue after that. – Riyan Fransen Nov 07 '17 at 13:28
  • Then you can use @Larme suggestion for bitmapping into structure. But also consider that `Data` is `Collection` and supports `subscript` with ranges, and enumerating over bytes (`UInt8`). – user28434'mstep Nov 07 '17 at 13:39
  • 3
    But *how* do you want to split it up? How many bits long is each piece? Is there padding? Is the data big endian or little endian? We cannot answer your question without knowing these details. – Hamish Nov 07 '17 at 13:46

0 Answers0