Here's an implementation of the Aho-Corasick algorithm in Swift:
3287 chars95 lines
You can use it like this:
195 chars8 lines
The algorithm builds a trie of all the search terms, and then traverses the trie to build failure links between nodes. The failure links allow the search to efficiently backtrack to the appropriate nodes when there is no match.
gistlibby LogSnag