Skip to content

Instantly share code, notes, and snippets.

@jonahaung
Created November 16, 2019 16:04
Show Gist options
  • Save jonahaung/c31eea7649cdfa639cbe4013cc11b380 to your computer and use it in GitHub Desktop.
Save jonahaung/c31eea7649cdfa639cbe4013cc11b380 to your computer and use it in GitHub Desktop.
Myanmar Numbers Converter
import Foundation
protocol MyanmarNumber {}
extension MyanmarNumber {
func toMyanmarNumber() -> String? {
guard let this = self as? NSNumber else {
return nil
}
let value = "\(this)".map { (char) -> Int in
let code = Int(UnicodeScalar(String(char))!.value)
return (code >= 48 && code <= 57) ? code + 4112 : code
}.reduce("") { "\($0)\(String(Character(UnicodeScalar($1)!)))" }
return value
}
}
extension Int : MyanmarNumber {}
extension Double : MyanmarNumber {}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment