Get Original Text (Swift 3)
Andre113 opened this issue · comments
Hello. I'm trying to access the original text from AKMaskField (ex: '2016/11/11' would be '20161111'). I tried to follow your solution, but it didn't work.
var template: String = ""
for block in self.field.maskObject {
template += block.template
}
println("Template text: \(template)")
First I couldn't access field.maskObject
and block.template
.
I looked into your code and changed fileprivate(set) var maskBlocks: [AKMaskFieldBlock] = [AKMaskFieldBlock]()
to open var maskBlocks: [AKMaskFieldBlock] = [AKMaskFieldBlock]()
and the same to template
, so I could access it.
However, the print is always the value of maskTemplate
, so I want to know if you could provide a new solution.
Thanks for your attention.
In your case, since it is only digits, you could use:
let template = text?.components(separatedBy: CharacterSet.decimalDigits.inverted).joined()
But the best solution would be a generic one =/
I am using this but I will try to contribute later with a better implementation.