bflora2
bflora2

Reputation: 753

Best way to handle 10k dictionary I want to be able to refer to?

I have a dictionary file that's about 10k lines. It stores a bunch of information that I want to be able to grab and refer to from time to time in my app. What is the best way to include this data in my app?

I tried making a .swift file where I just say:

let magicDict = [_10k lines of dictionary values_]

But that feels like the wrong way and it's slowed my build times to a crawl. (Is that because xcode is pulling that file into every one of my files?)

Should this be a model? Something else? It's just a bunch of static data.

Upvotes: 0

Views: 61

Answers (2)

Yuval Tal
Yuval Tal

Reputation: 653

I would create a static plist, json, xml or any other format that you feel comfortable with, and read it during runtime into a dictionary.

Upvotes: 0

Duncan C
Duncan C

Reputation: 131416

As JAL says, read it from a file. Plists are perfect for this purpose. Take a look at the NSDictionary methods NSDictionary(contentsOfFile:) and NSDictionary(contentsOf:). One takes a path, the other an URL.

Upvotes: 1

Related Questions