Skip to content

Commit

Permalink
- add token property
Browse files Browse the repository at this point in the history
  • Loading branch information
haithngn committed Jun 21, 2017
1 parent c3a9031 commit 1363ec8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
9 changes: 6 additions & 3 deletions Source/WSTag.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,20 @@ import Foundation
public struct WSTag: Hashable {

public let text: String

public let token: String

public init(_ text: String) {
public init(_ text: String,_ token: String) {
self.text = text
self.token = token
}

public var hashValue: Int {
return self.text.hashValue
return self.token.hashValue
}

public func equals(_ other: WSTag) -> Bool {
return self.text == other.text
return self.token == other.token
}

}
Expand Down
14 changes: 7 additions & 7 deletions Source/WSTagsField.swift
Original file line number Diff line number Diff line change
Expand Up @@ -389,16 +389,16 @@ open class WSTagsField: UIView {

// MARK: - Adding / Removing Tags

open func addTags(_ tags: [String]) {
tags.forEach() { addTag($0) }
open func addTags(_ tags: [(String, String)]) {
tags.forEach() { addTag($0, $1) }
}

open func addTags(_ tags: [WSTag]) {
tags.forEach() { addTag($0) }
}

open func addTag(_ tag: String) {
addTag(WSTag(tag))
open func addTag(_ tag: String,_ token: String) {
addTag(WSTag(tag, token))
}

open func addTag(_ tag: WSTag) {
Expand Down Expand Up @@ -456,8 +456,8 @@ open class WSTagsField: UIView {
repositionViews()
}

open func removeTag(_ tag: String) {
removeTag(WSTag(tag))
open func removeTag(_ token: String) {
removeTag(WSTag("", token))
}

open func removeTag(_ tag: WSTag) {
Expand Down Expand Up @@ -493,7 +493,7 @@ open class WSTagsField: UIView {
open func tokenizeTextFieldText() -> WSTag? {
let text = self.textField.text?.trimmingCharacters(in: CharacterSet.whitespaces) ?? ""
if text.isEmpty == false && (onVerifyTag?(self, text) ?? true) {
let tag = WSTag(text)
let tag = WSTag(text, text)
addTag(tag)
self.textField.text = ""
onTextFieldDidChange(self.textField)
Expand Down

0 comments on commit 1363ec8

Please sign in to comment.