How to prevent the user to write anything but English Ios - ios

I have an iOS app and I want to prevent the user from entering anything other than English characters in a textfield.
If not, is there a way I can convert the non-English characters into English characters.
Thanks in advance

It looks like this answer has been addressed in this previous post:
How do I restrict UITextField to English only? (Stopping Chinese pinyin input)
Wherein the suggestion is made, by user k_ppes, to use the following code:
tf.keyboardType = UIKeyboardType.ASCIICapable

Related

Translate UITextField input text into Spanish runtime

An iOS app which displaying wordpress blogs. There is search feature, App searches world-phress into API's data. Wordpress website contents are in Spanish language.
My issue is when user inputted text "Buho", app should search "Búho", "Buho", "buho", "búho" in Spanish data and display result according. Curretnly app is matching word "buho", not "búho".
On Wordpress website, same thing is possible, User can search either "Búho" or "Buho", all search result displayed.
How to translate UITextField's text value into Spanish, So I can easily search into NSArray and show result. Or is it possible to replace character set?
Simple english word searching is possible using NSArray filter, search into blog's title and text with particular text.
Like this:
let searchingWorld = self.searchBar.text!.lowercased()
let blogSearchResult = self.blogs.filter{ $0.title.lowercased().contains(searchingWorld) || $0.text.lowercased().contains(searchingWorld) || $0.tags.contains(searchingWorld) || $0.categories.contains(searchingWorld) }
self.blogs object is array of dictionary type object. {title, text, category, tags}
Not found any solution.
Any help greatly appreciated.
Punita
If I understand you correctly, you're not looking to translate to Spanish, but are looking how to do a so called diacritic insensitive search.
iOS has a search option to do that.
In the same way you can specify an option to do a case insensitive search.
Here're is an example that I hope helps.

How to append placeholder to textview/textfield after user begins editing

I am trying to create a textfield input, that forces the user to enter a email address but forces the domain (the domain logic is validated when the user enters return), so the user enters a email associated with that domain only. This needs to be very clear on the UI itself, I've tried using the UITextField but since the placeholder is cleared after the user starts editing it doesn't work so well. Here is a sample screenshot of the Slack app that shows similar textfield-
Eg. The user enters team domain, and ".slack.com" is appended to the user text.
Setting up a NSAttributedString as the textField.text from textField:shouldChangeCharactersInRange:replacementString: invocations will give you the desired behaviour.
When the user stars typing you can append the ending domain to what the user types. You can also play with attributed strings changing the color of the appended text so it looks as it's still part of the placeholder. This should be done intextField:shouldChangeCharactersInRange:replacementString:
Check the official documentation https://developer.apple.com/reference/uikit/uitextfielddelegate/1619599-textfield?language=objc
For setting the cursor in the desired position you can use UITextPosition which is extensively explained in this answer

How to make a customer keyboard insert attributed text (e.g., website link) in Swift?

I'm making a 3rd-party keyboard for the iPhone, and can get the keyboard to insert a specific string via:
(textDocumentProxy as UIKeyInput).insertText("\(string)")
Unfortunately the insertText function only takes a string argument - is there a way to make it take an NSAttributedString, or a workaround that allows me to put an NSAttributedString into the text field the user is typing into?
I basically want part of "string" to be the URL of my app on the app store.
Unfortunately this is not possible. You can only insert String / NSString objects from a keyboard extension.
One common workaround is to put it in
[UIPasteboard generalPasteboard];
but this relies on the user then long-pressing and pasting it into the text field themselves, which is a horrible UX and seems like overkill for your use-case. Maybe it would be sufficient to include the 'https://' in the URL and then the app the user is typing in should hopefully detect that it's a link and display it as such. That's not guaranteed though.

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 NSString - Creating upper case based on locale

My iOS application has language selection option.
Its a server based application that receives all the strings from server that are to be displayed in the app.
In one of the view, i've to convert text to "upper case", for that I'm using NSString's upperCaseString method. This is working good for English. But for other languages like French, Chinese, Russian, German etc, it might create problem. So, I've to use "uppercaseStringWithLocale" to provider appropriate upper case string.
My question is how to create the NSLocate and pass it to "upperCaseStringWithLocale" method based on the language name. I know what's the language of the app that user has selected. Can I create locale object based on language name.?
I think you are looking for:
NSString *theLocaleIdentifier = #"es_ES_PREEURO";
[[NSLocale alloc] initWithLocaleIdentifier:theLocaleIdentifier];

Resources