iOS Swift autocomplete dropdown with also own keywords - ios

I'm looking for a way to create a textfield with autocomplete and dropdown feature so that a user can also add a new keyword.
Similar to this JS-selector:
https://select2.github.io/examples.html#tags
The only difference is that my textfield should only accept one selection and no multiselect.
I've googled for open source or a payed widget for this, but mostly I found very old and not good looking stuff with Swift 1 and things like that.
So is there no fancy autocomplete-dropdown textfield which is simple to implement in my project?
Or is there a reason why there is so less stuff on a UI-object like the one I described?

There is no auto-complete widget, that I'm aware of at least.
But you can create your own:
pull the string from the input textfield.
compare it against an array of potential keywords
pull the range of the string, highlight the letters in the keywords
where the user completes without selecting a drop down, add keyword

Check this https://github.com/mnbayan/AutocompleteTextfieldSwift.
Really easy to use and implement. You just need to create the UITextField as this type and set the content to check.

I've written a simple auto-complete pop up view named SwiftAutoSuggestion
Add pod 'SwiftAutoSuggestion' in your pod file
Then, Run pod install.
More details an be found on the link.

And, just to add another stick onto the woodpile, I just released this (RVS_AutofillTextField).
It's a UITextField that has been extended to provide a "dropdown" table, that acts as an autocomplete source.

Related

iOS Custom Keyboard, Suggestions from txt file

I'm making a custom keyboard for lawyers, and trying to load law related words in suggestion/prediction bar on top the keyboard based on what user types. Just like in stock keyboard. I have searched around but did not find any concrete answer.
I want to display suggestions of law related terms that I have in a txt file, all words are sorted alphabetically.
DEMO
Here is what I have tried:
UILexicon
let myLexicon = NSMutableDictionary()
self.requestSupplementaryLexiconWithCompletion { (theLexicon: UILexicon!) -> Void in
let lexiconEntries = theLexicon.entries
// Completion handler
for item in lexiconEntries {
self.myLexicon.setObject(item.documentText, forKey: item.userInput)
}
}
This code just gives 23 nil objects.
UITextChecker This is an iOS class that is designed to spot spelling errors, which makes it perfect for knowing if a given word is real or not. This is seems to be mainly for autocorrection, not for suggestion. Correct me if I'm wrong please.
I cannot somehow make sense out of these two classes.
How do I tell custom keyboard, "Hey if user enters "V" show the top 3 words that start from V, then if user enter a, fill the suggestion bar with words that start with "Va" and so on.
EDIT: Looks like someone ran into same problem. Here is a quote how they solved it, I will update with code once I finish figuring this out myself.
However, this was far from the truth - in fact, Apple do not allow access to their dictionary full stop, only offering a UILexicon class instead as stated in their docs:
Make use of this class, along with a lexicon of your own design, to provide suggestions and autocorrections as users are entering text.
As it turns out, the UILexicon class only really contains contact names along with any shortcuts (like the default On My Way!) defined on the device. So before writing the logic for a keyboard, you first have to implement your own autocorrect library.
We browsed through a few external projects to see if we could include them in the keyboard - most notably Hunspell, which is used by OpenOffice, and Presage, an intelligent predictive text library.
I spent a long time integrating the C++ libraries with the code, but in the end, in order to keep complexity down, we opted to use a combination of UITextChecker (which provides some basic corrections) and our own custom dictionary, containing a few commonly mispelled words.
Link to the Article
Thanks!
You have to implement your own autocorrection system. UILexicon will only give you shortcuts the user has set up, words that they have added to the iOS Dictionary, and names of contacts. It has no awareness of any words that you yourself provide, whether in a txt file or in any other form.
If you want to use the TOMSSuggestionBar, it appears from the sample code that the onus is on you to convert your txt file into a core data model, and indicate to the suggestion bar how it is to interpret the contents of that model. You may also want to implement the data source protocol to get more fine grained control over the suggestions.
Autocorrection and next word prediction are not solved problems; I suggest you do your own research and find the solution that is best suited to your goals.

ios/xcode/coredata: How to mimic ajax call in objective c

For a tag system, when entering a new item, I'd like the user to start typing a letter or two and see possible tags...similar to how SO tags work on the website i.e. Ajax.
Is there a way to do this on IOS?
Basically the Add Item screen has some empty text fields where you put the name etc.
I'd like to have an additional empty field where as you enter letters you see possible tags appear below and can then select one to tag the item.
The tags would be served from an entity or table so there would have to be a call to core data to supply them based on the letters typed.
Do I have to implement a full blown tableview to do this? Or is there a way to make the possible tags show up below the textfield box.
Thanks for any suggestions.
You could try a third party development in order to make what you want. In a recent project I have used this one:
https://github.com/EddyBorja/MLPAutoCompleteTextField

Xcode - search scope to exclude files or path

If your project is big and has many localizations, sometimes you find view controllers by searching for text displayed on that view controller's view. But in doing so you get a lot of search results you don't need that can make finding the file you're searching for cumbersome:
If you're like me and do this a hundred times a day, you want to have a way to omit Localizable files from your searches, for example. How?
In the Find Navigator tab, click the current search scope directly underneath the search bar:
Click "New Scope..." and give it a name. I picked 'Workspace W/O Localizable":
Add a Path condition that 'matches regex'. You can use a negative regex to exclude paths with "Localizable" in it. The regex to use is this: ^((?!Localizable).)*$
That's it! Just click the new search scope under "SEARCH SCOPES" and it will be the new default.
Quick tip which is a solution for some. You can easily change this by clicking on a result and hitting "delete." This will remove the result or group of results from the list. It will not affect your code ;)
Quick tip for xCode 9.4. Create a search scope of this to search just the swift files in your project.

iOS - Look for and manipulate text field by tag?

I have 'inc' and 'dec' buttons for a series of fields in an iOS app that I am using to manipulate matching text fields. I've looked in all my references and can't quite get how to iterate through the text views by tag, and be able to manipulate them from there. I found how to at least list them out, but that doesn't quite finish the job.
I apologize for what may be an easy question, but I haven't found how to do it yet - is it possible, or do I have to write separate code for each button?
You don't need to use tags for this.
Create a reference to each object in the controller, assign them to an IBOutletCollection which you can then use to enumerate the objects:

auto_complete_for: prevent the first item from being auto-selected

The auto_complete_for dealio from script.aculo.us is great an all, but is there a way for me to selectively disable the fact that it always auto-selects the first item in the list?
The problem is that, if I want to type my own entry that is new, and novel, I don't want the first item in the list to be auto-selected. The reason is because when I TAB out of the field, it selects, and fills the text box with that first item.
I got around that, somewhat, by making the first item in the list the same as what I'm typing, but that's not perfect either, because the auto_complete list doesn't always update with every keystroke, depending on how fast I type. I've tried setting the list refresh rate to the lowest value (1 millisecond) but no go.
What I really want is an option in "auto_complete_for" that doesn't select that first item at all - the same way that Google Instant doesn't automatically select the first suggested search phrase - you have to arrow-down to select one.
Maybe I can do this via an HTML option that I'm missing?
Looking at the source, there doesn't appear to be an option for that, but I bet if you changed line 284 of controls.js to this.index = -1; it would do what you want.
Otherwise, it might be time to look for a different autocomplete widget.
If your requirements are too far away from the available plugin, then I guess there is no point in tinkering around. Its best to write your own JS code.
You might want to consider this: https://github.com/laktek/jQuery-Smart-Auto-Complete
or this : https://github.com/reinh/jquery-autocomplete
I'll add another alternative that works great with Rails 3:
http://github.com/crowdint/rails3-jquery-autocomplete
I recently implemented auto complete for more than a field for Rails 2.0.2.
The plugin I used is:- https://github.com/david-kerins/auto_complete . Not sure if it supports Rails 3.
I have also encountered issues on implementing the above scenario and have posted questions( Implementing auto complete for more than one field in Rails ; Implementing a OnClick kind of functionality and formatting wrt Rails Partial-Views ) on stackoverflow for the same, I have been lucky on getting things working for me based on my requirement.
Kindly refer to these questions, they might have relevance to your requirement.

Resources