This will be my first post. I hope am adhering to the communities guideline. Anyway, I've just started on Swift programming. I took on some task to fully immerse myself on practicing the language. I've been searching on an explanation or a guide in terms of building a tokenizer. I believe they call it tokenizer, it's similar to Gmail's implementation when you search/enter on the "To" field. I hope someone can help shed some light on this, perhaps point me to some direction. Thanks in advance!
-
why not just google "swift tokenizer" – Surely Jul 24 '16 at 04:43
-
Thanks @Surely, actually am not sure if it's called tokenizer. Am hoping to build some sort of a simple library. – Hyde Jul 24 '16 at 04:49
-
I think you should study up on NSPredicate before attempting your project http://nshipster.com/nspredicate/ I'm unfamiliar with term "tokenizer" within ios but it's possible that NSPredicate is capable of serving your intended purpose – markedwardmurray Jul 24 '16 at 05:07
-
@markedwardmurray thank you, I am familiar with NSPredicate mostly used it in string search and comparison it's really good. Like you am unfamiliar with using or the term Tokenizer, am not even sure if it's even called that. But basically, am looking for something similar to the method used in building/grouping list of contacts in a field, like the Gmail's "To" field or the Apple's email. – Hyde Jul 24 '16 at 05:14
-
if you're dealing with contacts, can't you just apply a predicate to CNContact objects? – markedwardmurray Jul 24 '16 at 05:18
-
@markedwardmurray thanks for awesome ideas. I looked up CNContacts however it's quite different. So the gist is, I have a UItextView, typing a character would search/fetch on an API for names, which will provide some sort of autosuggest. Was able to do the autosuggest part. My main direction now is to display those names in manner similar to Gmail's, which a name can be deleted/removed. http://i.stack.imgur.com/EYSnj.png – Hyde Jul 24 '16 at 05:36
-
@Hyde does that snapshot show a selected result, or a list of options in the search? – markedwardmurray Jul 24 '16 at 05:45
-
@markedwardmurray I would presume there's some sort of a tableView to select it from. In my project I have a tableView on which you can select it. For the life of me, am having a hard time displaying the tapped result similar to that image I've provided. Am really a noob on swift, so thank you for bearing with me. By the way, I grabbed that image on google, I think its an android screen. – Hyde Jul 24 '16 at 05:53
-
@Hyde moving the discussion to an answer because of text limits in comments – markedwardmurray Jul 24 '16 at 06:01
1 Answers
This has more to do with knowledge of Cocoa frameworks than of Swift. The way I would reproduce that example image from your comment in ios would be to read from an array of contact objects of some kind, pulling out a string value for the email address, and then programmatically creating a UIImage from snapshotting a UILabel set with the given text, font attributes, and grey background color. Helpful steps in this answer: How to create an image from UILabel?
Then taking that UIImage and converting it to an NSTextAttachment, building an NSAttributedString with each UIImage concatenated with commas and newlines, and setting the TextView's .attributedString property with the final string. You will need to use UITextView (and not UITextField) for multi-line input text. Helpful steps in this answer: How to add image and text in UITextView in IOS?

- 1
- 1

- 523
- 4
- 10
-
1thank you sir! This might be the direction am looking for. I'll try this approach and see how it goes. By the way, I saw 2 libraries unfortunately it's a written in Objective-C. Hopefully I can write similar on Swift. https://github.com/clusterinc/CLTokenInputView, https://github.com/zoonooz/ZFTokenField. I guess it's really called Tokenizer. – Hyde Jul 24 '16 at 06:11
-
oh interesting. according to the readme there is a Swift port of CLTokenInputView https://github.com/rlaferla/CLTokenInputView-Swift but it also looks like the original should be bridgeable – markedwardmurray Jul 24 '16 at 06:14
-
I didn't see that. Anyway, am still gonna try your approach. I really wanna have a broader understanding of swift. Thanks again, good sir! – Hyde Jul 24 '16 at 06:20