Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

store a large list of static strings (Swift)

I am making an app for iOS 8 with Swift. I need to store long lists of strings. These will need to be read at any time during the app. What is the easiest way to accomplish this? XML files, plain text files, binary files?

like image 663
quemeful Avatar asked May 22 '26 05:05

quemeful


1 Answers

The usual from Objective-C experiences applies. You can really use any of the methods you mention. Some comments:

  • XML: seems overkill. You would need a parser, etc.
  • Exception: Apple's property lists (which is also an XML format). You can read the entire list with a one-liner
  • Plain text: involves a few lines of code to read it, so it could be viable. It would be particularly easy to make the list in the first place (e.g. with excel or a text editor).
  • Binary: not recommended for strings.
  • Core Data: keeps the strings in a neat SQLite database, but is likely to be overkill as well.

e.g. for plist:

let wordList = NSArray(contentsOfFile: path)
like image 139
Mundi Avatar answered May 24 '26 20:05

Mundi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!