A simple library for macOS/iOS/tvOS - enabling fast, in memory, prefix based, string searching, using a Trie.
- macOS 10.11+
- iOS 9+
- tvOS 9+
StringSearchKit is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod "StringSearchKit"
Because it makes it really easy to implement Auto-Complete functionality in an application - as I did in my macOS™ app - Sequence Diagram
StringDictionary(withStrings: [String], preserveCase: Bool = false)
StringDictionary(withTextFileNamed: <A name of a text file in your Bundle>, preserveCase: Bool = false)
StringDictionary(withTextFilepath: <The path to a text file>), preserveCase: Bool = false
Using one of the initialisers above, create an instance of StringDictionary
.
When initialising from a file, it should simply contain one string per-line.
Strings are not limited to being single words - but are in the examples, for simplicity.
Example file contents :-
act
apologise
apology
app
apple
Once instantiated, use the StringDictionary
to quickly find strings (case-insensitively) with a given prefix.
let stringDictionary = StringDictionary(withStrings: ["act", "app", "apple", "apologise", "apology"])
let searchResults = stringDictionary.strings(withPrefix: "app")
// searchResults will then contain ["app", "apple"]
If you set preserveCase: true
in any of the init
methods (default is false
for backwards compatibility), the results will be returned in the same case that the original words were in when added.
For example:
let stringDictionary = StringDictionary(withStrings: ["Act", "App", "Apple", "Apologise", "Apology"], preserveCase: true)
let searchResults = stringDictionary.strings(withPrefix: "app")
// searchResults will then contain ["App", "Apple"]
Mike O. Abidakun github@mikeosoft.co.uk
StringSearchKit is available under the MIT license. See the LICENSE file for more info.