Kashif
Kashif

Reputation: 4632

Swift Array size limit and Xcode compile limits

I have extracted OSX English language dictionary and want to use it in my Swift iPhone app. It has about 236,000 words which I have added to a swift string array.

When I try to run the build, it takes a long time to compile and then throws Segmentation Fault 11

Is this because the array is too big?

Am I going the correct path trying to add english dictionary in my project?

Upvotes: 0

Views: 3243

Answers (2)

Kashif
Kashif

Reputation: 4632

I was able to solve this problem by adding the actual dictionary text file into my xcode project. then utilize below code to fill words from the file to an array. it was pretty fast.

let path = NSBundle.mainBundle().pathForResource("dict2", ofType: "txt")
let dico = String(contentsOfFile: path!, encoding: NSUTF8StringEncoding, error: nil)
let dict = dico!.componentsSeparatedByString("\n")

Hope it helps someone.

Upvotes: 1

AlBlue
AlBlue

Reputation: 24040

You should probably not store this as a single string. There are more efficient data structures that you can use, such as a trie. You should also consider not loading the entire content into memory at one point but be able to navigate it from the filesystem.

Upvotes: 1

Related Questions