I have an array of English words that is about 275,000 elements long that I need to use for my iOS app written in Swift. However, Xcode doesn't seem to be able to handle such a large (3+ MB) file. The file will not open in Xcode, and when I attempt to compile the app, it seems to compile indefinitely and never build.
How should I handle this large amount of data?
Don't put a huge literal array in your swift source code.
Instead, create a text file, drag that into your project as a resource, then open that and convert it into an array at runtime using components(separatedBy:)
.
For speed and storage efficiency you could instead write a conversion utility that reads your text file and uses components(separatedBy:)
to convert it to an Array
of Strings
. Then you could write the array of Strings
to a binary plist.
You could then drag the plist file into your project as a resource, and write code that reads the plist file into an Array
at launch.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With