Newbie in swift: Problem in Mac OS to read from files with mixed multiple types

I am trying to read from a file in swift with mixed data type. As an example:

  1. 80 eight bit coded characters, no line feed
  2. Another 60 eight bit coded characters, no line feed
  3. 1024 eight bit, unsigned numbers
  4. Another 160 eight bit coded characters, no line feed

This is just a short example - the real thing is much bigger: About 270 MB.
Looking for a fast, efficient way to read that, and put it in a struct.

Thanks for helping in advance !

Your best friends will be FileHandle and Data. They will let you read byte blocks. If your structure doesn’t change, you can load up into Swift structs.

If you are just working with text, maybe something like a StreamReader will work for you?

Based on your file size, please consider reading using GCD, so you don’t lock up the main/GUI thread.

This topic was automatically closed after 166 days. New replies are no longer allowed.