Giter Club home page Giter Club logo

acrautocomplete's Introduction

ACRAutoComplete

An auto-complete text library for iOS.

CI Status Version License Platform

A simple Trie structure implementation in Swift for indexing and searching words.

This library does not include a user interface, it was built to be a simple easy to use auto-completion tool. Originally, it written for MessMoji.

Author

Andrew Crookston

Please send me a tweet if you like this library or have questions or feedback: @acr

Example

The Example project contains a full working implementation of the library including a table view, and an input field to search the SOWPODS word list. If you are looking for an auto-complete solution with a UI, take a look at the Example project.

To run the example project, clone the repo, and run pod install from the Example directory first.

Requirements

The library was written for iOS. It has no external requirements and it's possible it works on macOS or other Swift platforms, but this has not been tested.

Installation

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

pod "ACRAutoComplete"

Usage

First add the protocol to whatever object you wish to index, for example with a Word class, and add the required methods:

import ACRAutoComplete

class Word : Searchable {
    let word : String
    init(_ word: String) {
        self.word = word
    }

    // From Searchable protocol
    func keywords() -> [String] {
        return [word]
    }

    // Hashable
    var hashValue: Int { return word.hashValue }

    static func == (lhs: Word, rhs: Word) -> Bool {
        return lhs.id == rhs.id
    }
}

In your controller or place where you wish to use the index. Create an `AutoComplete` object with the `Word` class:
```swift
let autocomplete = AutoComplete<Word>()

Insert the objects you wish to index:

let football = Word("Football")
autocomplete.insert(football)

Finally, when needed, search the index for any matching objects:

autocomplete.search("foot") // -> [Word("Football")]

Metrics

For testing, the SOWPODS word list has been used. It contains 267753 words which takes roughly 5 seconds to index in the iOS Simulator. Searching is very quick and will take less than 200ms, depeding .

License

ACRAutoComplete is available under the MIT license. See the LICENSE file for more info.

The example project (not the Pod) includes a SOWPODS word file which is used for testing. The license of the SOWPODS file when downloaded was unknown but was labeled "open source".

acrautocomplete's People

Contributors

acrookston avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.