Getting Autocomplete to Work in Swift

Getting autocomplete to work in swift

Replace your searchAutocompleteEntriesWithSubstring function content with the one below. I hope it would help you.

func searchAutocompleteEntriesWithSubstring(substring: String)
{
autocompleteUrls.removeAll(keepCapacity: false)

for curString in pastUrls
{
var myString:NSString! = curString as NSString

var substringRange :NSRange! = myString.rangeOfString(substring)

if (substringRange.location == 0)
{
autocompleteUrls.append(curString)
}
}

autocompleteTableView.reloadData()
}

Trick to get appropriate auto complete method in xcode

You just start typing cellForRowAtIndexPath you will get that particular method. No need to type from tableView...blah blah... Just type the methods main phrase, then you will get correct method in suggestion.

Sample Image

Thanks:)

Xcode 9 Autocomplete Not Working 100% - Partially Working

Deleting the DERIVED DATA folder seemed to fix my issue. Thanks to this post: swift println() not showing autocomplete options while writting code

How to create autocomplete text field in Swift

I did something like this in my app for looking up contacts. I will pseudo code this out for you to understand the concept:

1) Capture the characters entered into the textfield by the enduser

2) At some character count entered decide to query the server to return all entries that match - choose the character count you are comfortable with (I chose around 3-4 characters). Fewer returns more, more returns less obviously...up to you, perf and UX considerations.

3) Put the results of this server query into an array on the client. This will be your superset from which you will offer the suggestions to the user.

4) After each subsequent character entered into the text field you will now filter the array (array.filter()) by character string entered to this point.
5) tableView.reloadData() against the filtered array at each character entered.

6) I use a dataFlag variable to determine what datasource to show in the tableview depending on what the user is doing.

Note: You only query the server once to minimize perf impact

// this function is called automatically when the search control get user focus
func updateSearchResults(for searchController: UISearchController) {
let searchBar = searchController.searchBar
if searchBar.text?.range(of: "@") != nil {
self.getUserByEmail(searchBar.text!)
}
if searchController.searchBar.text?.characters.count == 0 && dataFlag != "showParticipants" {
dataFlag = "showInitSearchData"
self.contacts.removeAll()
self.participantTableView.reloadData()
}
if dataFlag == "showInitSearchData" && searchController.searchBar.text?.characters.count == 2 {
self.loadInitialDataSet() {
self.dataFlag = "showFilteredSearchData"
}
}
if dataFlag == "showFilteredSearchData" {
self.filterDataForSearchString()
}

}

// filter results by textfield string
func filterDataForSearchString() {
let searchString = searchController.searchBar.text
self.filteredContacts = self.contacts.filter({
(contact) -> Bool in
let contactText: NSString = "\(contact.givenName) \(contact.familyName)" as NSString

return (contactText.range(of: searchString!, options: NSString.CompareOptions.caseInsensitive).location) != NSNotFound
})

DispatchQueue.main.async {
self.participantTableView.reloadData()
}
}

Xcode autocomplete does not work in Sources folder of Swift playgrounds

In order to enable autocompletion, you can embed your Playground in a regular Xcode project (e.g. an iOS application). I recommend creating a dummy project for that purpose. Simply drag and drop your playground in this dummy project and make sure to check "Add to target".

Then you can navigate to

Target -> Build Phases -> Compile Sources -> + -> Add other

and add all the files from your source folder. Please note, that you don't need to actually copy the files, a reference is enough for this purpose.

After this process all your source files are built against this dummy target and you can use autocompletion as usual. As far as I know, this is the best practice for debugging Playgrounds right now. Anyway I am curious, if there is an easier way to achieve that.

Place auto complete is not working after updating to version 3.0.2 - Google iOS sdk

Got the access from business people, accepted the privacy policy and I couldn't find the appkey in credentials which they have shared earlier.
Now I started using iOS key (auto created by Google Service) which working perfectly fine with updated sdk version i.e 3.0.3

Sample Image



Related Topics



Leave a reply



Submit