TextField with smart suggestion

Overview

AutoCompleteTextField

CI Status Version License Carthage compatible Platform

ezgif com-resize 1

Features

  • Provides a subclass of UITextField that has suggestion from input
  • Has autocomplete input feature
  • Data suggestion are provided by users
  • Enable store smart domains
  • Optimized and light weight

Requirements

  • iOS 10.0+
  • Xcode 11+
  • Swift 5+

Installation

CocoaPods

You can use CocoaPods to install AutoCompleteTextField by adding it to your Podfile:

pod "AutoCompleteTextField"

Carthage

Create a Cartfile that lists the framework and run carthage bootstrap. Follow the instructions to add $(SRCROOT)/Carthage/Build/iOS/AutoCompleteTextField.framework to an iOS project.

github "nferocious76/AutoCompleteTextField"

Manually

  1. Download and drop /Pod/Classesfolder in your project.
  2. Congratulations!

Usage

// Initializing `AutoCompleteTextField` 
let myTextField = AutoCompleteTextField(frame: CGRect(x: 20, y: 64, width: view.frame.width - 40, height: 40), dataSource: `YourDataSource`, delegate: `YourDelegate`)

// Setting `dataSource`, it can be set from the XCode IB like `TextFieldDelegate` in which will appear as `actfDataSource`
myTextField.dataSource = `YourDataSource`

// Setting delimiter (optional). If set, it will only look for suggestion after the delimiter
myTextField.setDelimiter("@")

// Show `AutoCompleteButton`
myTextField.showAutoCompleteButtonWithImage(UIImage(named: "checked"), viewMode: .whileEditing)

// Providing data source to get the suggestion from inputs
func autoCompleteTextFieldDataSource(_ autoCompleteTextField: AutoCompleteTextField) -> [ACTFWeightedDomain] {

    return weightedDomains // AutoCompleteTextField.domainNames // [ACTFDomain(text: "gmail.com", weight: 0), ACTFDomain(text: "hotmail.com", weight: 0), ACTFDomain(text: "domain.net", weight: 0)]
}

ACTFDomain

ACTFDomain is struct type that conforms to the Codable. User can store and retrieve smart domains.

One example may be 'gmail.com' and 'georgetown.edu'. Users are more likely to have a 'gmail.com' account so we would want that to show up before 'georgetown.edu', even though that is out of alphabetical order.

ACTFDomain is sorted based on its usage.

This is just one example. Manually providing a suggestion gives more flexibility and does not force the usage of an array of strings.

// Usage
let g1 = ACTFDomain(text: "gmail.com", weight: 10)
let g2 = ACTFDomain(text: "googlemail.com", weight: 5)
let g3 = ACTFDomain(text: "google.com", weight: 4)
let g4 = ACTFDomain(text: "georgetown.edu", weight: 1)

let weightedDomains = [g1, g2, g3, g4] // [ACTFDomain]

// Storing

// store single
if g1.store(withKey: "Domain") {
    print("Store success")
}

// store multiple
if ACTFDomain.store(domains: weightedDomains, withKey: "Domains") {
    print("Store success")
}

// Retrieving

// retrieved single
if let domain = ACTFDomain.domain(forKey: "Domain") {
    print("Retrieved: ", domain)
}

// retrieved multiple
if let domains = ACTFDomain.domains(forKey: "Domains") {
    print("Retrieved: ", domains)
}

Contribute

We would love for you to contribute to AutoCompleteTextField. See the LICENSE file for more info.

Author

Neil Francis Ramirez Hipona, [email protected]

About

This project was inpired by 'HTAutocompleteTextField' an Objc-C framework of a similar feature.

License

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

Comments
  • autoCompleteTextField. emailDomain

    autoCompleteTextField. emailDomain

    I believe that most people will use AutoCompleteTextField as an autocomplete for emails, so instead of having them copy and paste that huge domainNames array, we could have something like that:

    public func autoCompleteTextFieldDataSource(autoCompleteTextField: AutoCompleteTextField) -> [String] {
    
            return autoCompleteTextField.emailDomain
    }
    
    opened by lfarah 8
  • Carthage support

    Carthage support

    opened by TofPlay 4
  • Swiftlint

    Swiftlint

    I'd be cool to add Swiftlint and it's very easy to install. I already fixed all the Swiftlint warnings for AutoCompleteTextField, so It's all about installing and then I can make a pull request 😄

    opened by lfarah 4
  • Filter datasource array from smallest string to biggest

    Filter datasource array from smallest string to biggest

    By doing that, we are always autocompleting the smallest possible option, avoiding errors in compound city names, for example.

    My case

    User wants to type "Salvador" (city in Brazil)

    My DataSource array:

    ["sĂŁo Paulo", "salvador do Sul", "macapa", "salvador"]

    Problem:

    Salvador do sul is autocompleted instead of Salvador because it goes first in the array, and since Salvador has less characters, it will never autocomplete.

    Solution

    always filter datasource from the smallest string to the biggest, so every single string will have the chance to be autocompleted

    opened by lfarah 3
  • autoCompleteTextFieldDataSource string starting with Capital letter bug

    autoCompleteTextFieldDataSource string starting with Capital letter bug

    AutoCompleteTextField won't autocomplete if a string has it's initial character Capital. Array tested: ["SĂŁo Paulo", "Salvador", "Macapa", "Salvador do Sul"] Tried to use ignoreCase = true, but it didn't work

    opened by lfarah 2
  • Return button doesn't work on Example app

    Return button doesn't work on Example app

    In order to autocomplete a textfield, the user has to press the Return button. The problem is that the return button isn't working in the Simulator right now. The only way it works is by pressing tab.

    opened by lfarah 2
  • Allowing user to change color of suggestion text label

    Allowing user to change color of suggestion text label

    I didn't like the way of being forced to use same color for suggestion/autocomplete label, so I've removed the textColor observer and added another variable with suggestionColor that manipulates that.

    opened by patryk-sredzinski 1
  • Added manually providing autocomplete suggestion

    Added manually providing autocomplete suggestion

    Added a new datasource called AutoCompleteTextFieldManualDataSource that allows for manually providing autocomplete suggestions. This allows for more advanced sorting beyond just alphabetical, but must be used carefully (prefix of suggestion must match string to be replaced).

    opened by aj-bartocci 1
  • Manual Installation

    Manual Installation

    CocoaPods is an awesome tool and make our life really easier, but there are some devs who still don't know how to use them.

    It would be cool to add the Manual installation guide in your README.md. You can take a look at my iOS Readme Template to see how you can do it.

    opened by lfarah 1
  • Small changes

    Small changes

    These are a couple small changes that I needed to use AutoCompleteTextField in my project.

    1. The pod spec for including xcassets needed to be tweaked or it the checkmark images wouldn't be bundled.

    2. I use RxSwift and if the user let the text field be autocomplete it wasn't registering the correct value in RxSwift. Sending a value changed action event fixed it for me.

    Thank you for the work you've put into this & sorry that the PR items aren't separated. I did the work all on one branch and didn't think about it until it was too late.

    opened by samus 0
  • Swift 3 and SwiftPM support

    Swift 3 and SwiftPM support

    opened by TofPlay 4
Owner
Neil Francis Ramirez Hipona
Software Engineer / Developer
Neil Francis Ramirez Hipona
Floating-textfield-swiftui - Floating textfield With SwiftUI

floating_textfield-swiftui Hey, Guys welcome to this tutorial. In this complete

null 1 Feb 11, 2022
DTTextField is a custom textfield with floating placeholder and error label

DTTextField Introduction DTTextField is a UITextField library with floating placeholder and error label. Floating placeholder inspired from JVFloatLab

Dhaval Thanki 310 Jan 5, 2023
Floating Label TextField for SwiftUI. FloatingLabelTextFieldSwiftUI

FloatingLabelTextFieldSwiftUI FloatingLabelTextFieldSwiftUI is a small and lightweight SwiftUI framework written in completely swiftUI (not using UIVi

Kishan Raja 337 Jan 2, 2023
A custom TextField with a switchable icon which shows or hides the password and enforce good password policies

PasswordTextField A custom TextField with a switchable icon which shows or hides the password and enforces good password policies, written in Swift. ⭐

Chris Jimenez 304 Dec 29, 2022
A SwiftUI TextField with a prompt (or placeholder) that floats above the text field when active or not empty. Requires iOS 15.

FloatingPromptTextField A prompt is the label in a text field that informs the user about the kind of content the text field expects. In a default Tex

Emilio PelĂĄez 43 Nov 3, 2022
A floating label style for SwiftUI's TextField.

FloatingLabelTextFieldStyle A floating label style for TextField with support for displaying error messages. Requirements iOS 15.0+ macOS 12.0+ Instal

Red Davis 13 Aug 22, 2022
Simple placeholder move textfield

PlaceholderTextField Example To run the example project, clone the repo, and run pod install from the Example directory first. Requirements iOS 11.0 o

null 6 Mar 9, 2022
Elegant SwiftUI phone number textField.

iPhoneNumberField ☎️ Format phone numbers as they're typed—entirely in SwiftUI. ?? Get Started | Examples | Customize | Features | Install | And it's

Seyed Mojtaba Hosseini Zeidabadi 358 Dec 30, 2022
An optional TextField Replacement for SwiftUI

TextInputView A TextField Replacement In his excellent YouTube tutorial series on Building SwiftUI Components, Peter Friese (@peterfriese on Twitter)

Stewart Lynch 6 Aug 9, 2022
This is the demo repository for having floating TextField in swift UI

ed-floating-field-swiftui This is the demo repository for having floating TextField in swift UI The inputs fields should not be empty Validations for

Patrick 1 May 26, 2022
TextField with DropDown support using UIPickerView

IQDropDownTextField TextField with DropDown support using UIPickerView Installing Install using cocoapods. Add in your Podfile: pod 'IQDropDownTextFie

Mohd Iftekhar Qurashi 301 Jun 29, 2022
Library that allows you binding `enabled` property of button with textable elements (TextView, TextField)

What is NxEnabled? It's a fairly common case, when the enabled state of button depends on some textable elements such as TextView, TextField. So this

Nikita Ermolenko 33 Sep 20, 2021
Awesome TextField is a nice and simple libriary for iOS and Mac OSX

Awesome TextField is a nice and simple libriary for iOS and Mac OSX. It's highly customisable and easy-to-use tool. Works perfectly for any registration or login forms in your app.

Alexander Shoshiashvili 225 Nov 21, 2022
Apple TextField created according to the Material.IO guidelines of 2019. Featured at Medium.

CocoaTextField Highly customizable text field created according to Material.IO guidelines. Minimum iOS version 11.0 Carthage github "edgar-zigis/Cocoa

Edgar Žigis 266 Nov 26, 2022
TTextField is developed to help developers can initiate a fully standard textfield including title, placeholder and error message in fast and convinient way without having to write many lines of codes

TTextField is developed to help developers can initiate a fully standard textfield including title, placeholder and error message in fast and convinient way without having to write many lines of codes

Nguyen Duc Thinh 7 Aug 28, 2022
Floating-textfield-swiftui - Floating textfield swiftui: Floating field with multiple icons

floating_textfield-swiftui Hey, Guys welcome to this tutorial. In this complete

Patrick 0 Jan 2, 2022
Floating-textfield-swiftui - Floating textfield With SwiftUI

floating_textfield-swiftui Hey, Guys welcome to this tutorial. In this complete

null 1 Feb 11, 2022
My project about a suggestion field in swiftUI

SuggestionTextFieldMenu-SwiftUI My project about a suggestion field in swiftUI This is how it looks like! You can fill an array of objects and decide

Gabriele Cusimano 10 Oct 20, 2022
BMI-Calculator - An app which calculates the BMI and gives suggestion

BMI-Calculator An app which calculates the BMI and gives suggestion with MVC pat

null 0 Jan 19, 2022
Guaka - Smart and beautiful POSIX compliant CLI framework for Swift.

Guaka - Smart and beautiful POSIX compliant CLI framework for Swift. It helps you create modern and familiar CLI apps in the vein of widely used proje

Omar Abdelhafith 1.1k Dec 24, 2022