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

**URL:** <https://forums.kodeco.com/t/newbie-in-swift-problem-in-mac-os-to-read-from-files-with-mixed-multiple-types/78420>\
**Category:** Swift\
**Created:** [August 7, 2019, 5:26am UTC](https://forums.kodeco.com/t/newbie-in-swift-problem-in-mac-os-to-read-from-files-with-mixed-multiple-types/78420 "2019-08-07T05:26:09Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![mmim](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/mmim/32/81494_2.png) [@mmim](https://forums.kodeco.com/u/mmim)\
**Post date:** [August 7, 2019, 5:26am UTC](https://forums.kodeco.com/t/newbie-in-swift-problem-in-mac-os-to-read-from-files-with-mixed-multiple-types/78420/1 "2019-08-07T05:26:09Z")

</div>

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 !

---

<div class="post-metadata">

**Author:** ![robertomachorro](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/robertomachorro/32/111603_2.png) [@robertomachorro](https://forums.kodeco.com/u/robertomachorro)\
**Post date:** [August 7, 2019, 12:27pm UTC](https://forums.kodeco.com/t/newbie-in-swift-problem-in-mac-os-to-read-from-files-with-mixed-multiple-types/78420/2 "2019-08-07T12:27:36Z")

</div>

Your best friends will be [FileHandle](https://developer.apple.com/documentation/foundation/filehandle) and [Data](https://developer.apple.com/documentation/foundation/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](https://gist.github.com/klgraham/6fe11ed1e3fe075f5ffc8b7ca350bce4) will work for you?

Based on your file size, please consider reading using [GCD](https://www.raywenderlich.com/5370-grand-central-dispatch-tutorial-for-swift-4-part-1-2), so you don’t lock up the main/GUI thread.

---

<div class="post-metadata">

**Author:** ![system](https://s3.amazonaws.com/cdn.raywenderlich.com/community/forum-assets/noun-game-ghost-878668.png) [@system](https://forums.kodeco.com/u/system)\
**Post date:** [January 20, 2020, 9:26pm UTC](https://forums.kodeco.com/t/newbie-in-swift-problem-in-mac-os-to-read-from-files-with-mixed-multiple-types/78420/3 "2020-01-20T21:26:10Z")

</div>

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