diff --git a/Sources/TokenTextView/Token.swift b/Sources/TokenTextView/Token.swift index feb835d..eb4c0fd 100644 --- a/Sources/TokenTextView/Token.swift +++ b/Sources/TokenTextView/Token.swift @@ -1,8 +1,8 @@ import Foundation -struct Token: Codable { - let name: String - let identifier: String +public struct Token: Codable { + public let name: String + public let identifier: String } class TokenInstance: NSCopying, Codable { diff --git a/Sources/TokenTextView/TokenTextView.swift b/Sources/TokenTextView/TokenTextView.swift index 860492a..443f58d 100644 --- a/Sources/TokenTextView/TokenTextView.swift +++ b/Sources/TokenTextView/TokenTextView.swift @@ -1,19 +1,19 @@ import UIKit -final class TokenTextView: UITextView { +public class TokenTextView: UITextView { // MARK: Public properties - var tokenAttributes: TokenTextViewAttributes - var textAttributes: TokenTextViewAttributes + public var tokenAttributes: TokenTextViewAttributes + public var textAttributes: TokenTextViewAttributes - var tokenList: [Token] = [Token]() { + public var tokenList: [Token] = [Token]() { didSet { tokenizeText() } } - var templatedText: String { + public var templatedText: String { // Ensure all tokens ranges have been updated guard tokenInstances.first(where: {$0.range.upperBound - 1 >= text.count}) == nil else { print("TokenTextView: Failed to create templated text.") @@ -35,7 +35,7 @@ final class TokenTextView: UITextView { // MARK: Setup - init(text: String? = nil, + public init(text: String? = nil, tokenList: [Token] = [], tokenOpen: String = "{{", tokenClose: String = "}}", @@ -69,7 +69,7 @@ final class TokenTextView: UITextView { // MARK: Public methods - func insertToken(_ token: Token, at insertRange: NSRange? = nil) { + public func insertToken(_ token: Token, at insertRange: NSRange? = nil) { let location = insertRange != nil ? (insertRange?.location)! : selectedRange.location let tokenRange = NSRange(location: location, length: token.name.count) diff --git a/Sources/TokenTextView/TokenTextViewAttributes.swift b/Sources/TokenTextView/TokenTextViewAttributes.swift index 12971a2..3329521 100644 --- a/Sources/TokenTextView/TokenTextViewAttributes.swift +++ b/Sources/TokenTextView/TokenTextViewAttributes.swift @@ -1,13 +1,13 @@ import UIKit -struct TokenTextViewAttributes { - var backgroundColor: UIColor - var foregroundColor: UIColor - var font: UIFont - var kern: Int? - var paragraphStyle: NSMutableParagraphStyle? +public struct TokenTextViewAttributes { + public var backgroundColor: UIColor + public var foregroundColor: UIColor + public var font: UIFont + public var kern: Int? + public var paragraphStyle: NSMutableParagraphStyle? - var dictionary: [NSAttributedString.Key: Any] { + public var dictionary: [NSAttributedString.Key: Any] { var dictionary = [NSAttributedString.Key.backgroundColor: backgroundColor, NSAttributedString.Key.foregroundColor: foregroundColor, NSAttributedString.Key.font: font, @@ -19,4 +19,12 @@ struct TokenTextViewAttributes { return dictionary } + + public init(backgroundColor: UIColor, foregroundColor: UIColor, font: UIFont, kern: Int? = nil, paragraphStyle: NSMutableParagraphStyle? = nil) { + self.backgroundColor = backgroundColor + self.foregroundColor = foregroundColor + self.font = font + self.kern = kern + self.paragraphStyle = paragraphStyle + } }