-1

I want to add a text field where users can enter keywords. I want them to be suggested/parsed in a manner similar to websites like Soundcloud (and Stack Overflow etc). Are there any existing open source projects that do this I could import? What I am looking for is something like this image picker: https://github.com/mikaoj/BSImagePicker but for this keyword task.

this is what I want

Thanks!

noizybrain
  • 155
  • 1
  • 15
  • explain your requirement in brief. – sanjeet Jan 11 '16 at 05:49
  • What are you confused about? I want a text field (UITextField, I guess) where users enter keywords. I want a tappable suggestion to appear as a keyword is entered. I want confirmed keywords to appear as boxes that can be deleted. Just like entering keywords on this website, for example. I am asking if this has been implemented for use as a library in other projects, such as this Photos picker: https://github.com/mikaoj/BSImagePicker – noizybrain Jan 11 '16 at 06:00

2 Answers2

1

One way that I have implemented a search by keyword type feature is to have a table view underneath a UITextField, displaying a filtered list of possible matches as you enter text.

The link below has an answer which filters an array of strings. Note that you may wish to use "containsString" instead of "rangeOfString".

Check if array contains part of a string in Swift?

I don't know much about libraries or how Soundcloud does it, but I think a keyword based search is not too hard to implement if you are feeling energetic.

Community
  • 1
  • 1
mcfisty
  • 187
  • 10
1

For doing the thing you want, You first require list of all available keywords. Once you have array of keywords, perform the following steps.

  1. Implement textfield's delegate, method named textfield:shouldChangeTextInRange ....
  2. assign textfield's delegate to self
  3. Now, in above delegate method, create new string that is going to generate
  4. Now apply NSPredicate to search for in keywordsArray
  5. From the output of keywords filtered array, show whichever you wants to
Mehul Thakkar
  • 12,440
  • 10
  • 52
  • 81
  • Cool, NSPredicate. I'd never heard of that and it looks hella useful! – noizybrain Jan 11 '16 at 06:27
  • For your knowledge, whenever you want to perform search: use "NSPredicate", whenever you want to perform sorting, use "NSSortDescriptor", these 2 are very useful classes, but usually developers dont look into it and tries by using for-loops – Mehul Thakkar Jan 11 '16 at 06:30