Latest 0.5.1
License Apache 2
Platforms ios 9.0, osx 10.10, watchos 2.0, tvos 9.0, requires ARC

CI Status
Code Coverage
Carthage compatible
Swift 3.0.x
PRs Welcome


The majority of the fuzzy matching logic included in this project is taken from Neil Fraser’s google-diff-match-patch


Matching on Strings

FuzzyMatchOptions can be passed to any of these methods to alter how the strict or loose the fuzzy matching algorithm operates.

  • threshold in FuzzyMatchOptions defines how strict you want to be when fuzzy matching. A value of 0.0 is equivalent to an exact match. A value of 1.0 indicates a very loose understanding of whether a match has been found.
  • distance in FuzzyMatchOptions defines where in the host String to look for the pattern.
    "abcdef".fuzzyMatchPattern("ab") // returns 0
    "abcdef".fuzzyMatchPattern("z") // returns nil
    "🐶🐱🐶🐶🐶".fuzzyMatchPattern("🐱") // returns 1

Matching on Arrays of Strings

Returns a new instance of an Array which is sorted by the closest fuzzy match. Does not sort the host Array in place. Will always return the same number of elements that are found in the host Array.

["one", "two", "three"].sortedByFuzzyMatchPattern("on")
// returns ["one", "two", "three"]
["one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten"].sortedByFuzzyMatchPattern("on")
// returns ["one", "nine", "two", "four", "seven", "ten", "three", "five", "six", "eight"]
["one", "one", "two"].sortedByFuzzyMatchPattern("on")
// returns ["one", "one", "two"]

Providing a confidence level

A confidence level allows client code to understand how likely the fuzzy searching algorithm is to find a pattern within a host String. confidenceScore returns a Double which indicates how confident we are that the pattern can be found in the host String. A low value (0.001) indicates that the pattern is likely to be found. A high value (0.999) indicates that the pattern is not likely to be found.

"Stacee Lima".confidenceScore("SL") // returns 0.5
"abcdef".confidenceScore("g") // returns nil
"🐶🐱🐶🐶🐶".confidenceScore("🐱") // returns 0.001
"🐶🐱🐶🐶🐶".confidenceScore("🐱🐱🐱🐱🐱") // returns 0.8


All documentation is maintained at Cocoadocs


  • iOS >= 9.0
  • MacOS >= 10.10
  • watchOS >= 2.0
  • tvOS >= 9.0



FuzzyMatchingSwift is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod "FuzzyMatchingSwift"


FuzzyMatchingSwift is available via Carthage. To install, just add this entry to your Cartfile:

github "seanoshea/FuzzyMatchingSwift"

Once you’ve altered your Cartfile, simply run carthage update. Check out the instructions in Carthage’s README for up to date installation instructions.


SwiftLint can be run on the codebase with:

swiftlint lint --config .swiftlint.yml


seanoshea, [email protected] See the Acknowledgements section for the original basis for this code.


FuzzyMatchingSwift is available under the Apache 2 license. See the LICENSE file for more info.


See the Contributing Instructions for details.

Latest podspec

    "name": "FuzzyMatchingSwift",
    "version": "0.5.1",
    "summary": "Fuzzy matching String extensions.",
    "description": "FuzzyMatchingSwift provides String extensions which allow developers to find similar Strings in Strings and Arrays of Strings.",
    "homepage": "",
    "license": {
        "type": "Apache 2",
        "file": "LICENSE"
    "authors": {
        "seanoshea": "[email protected]"
    "source": {
        "git": "",
        "tag": "0.5.1"
    "social_media_url": "",
    "requires_arc": true,
    "compiler_flags": "-whole-module-optimization",
    "platforms": {
        "ios": "9.0",
        "osx": "10.10",
        "watchos": "2.0",
        "tvos": "9.0"
    "source_files": "FuzzyMatchingSwift/Classes/**/*",
    "pushed_with_swift_version": "3.0"

Pin It on Pinterest

Share This