简体   繁体   中英

Loading trie first time the app opens

I am working on a custom ios keyboard. For the dictionary of words, I have implemented trie for autocorrect. Trie is coded in objective c as well. I have 100k wordlist. I want to load the trie only the first time the app opens and it should get stored permanently. Is it possible?

What do you mean with loading only once, downloading?

Given that you download the data (let's assume as a txt from the internet) you can build up your trie and serialize that via NSKeyedArchiver and also restore it.

Trie *wordsTrie = [[Trie alloc]initWithUrl:@"https://www.internet.com/words.txt"]];
NSData *data = [NSKeyedArchiver archivedDataWithRootObject:wordsTrie];

/* persist the data ... */

Trie *restoredWordsTrie = [NSKeyedUnarchiver unarchiveObjectWithData:data];

More about archiving objects can be found here: https://developer.apple.com/library/content/documentation/General/Conceptual/DevPedia-CocoaCore/Archiving.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM