The problem with use NumberFormatteris that it will ignore other non-digital characters, for example if you Hello ١٢٣have one 123. To save other characters and only convert numeric, you can use the following:
public extension String {
public var replacedArabicDigitsWithEnglish: String {
var str = self
let map = ["٠": "0",
"١": "1",
"٢": "2",
"٣": "3",
"٤": "4",
"٥": "5",
"٦": "6",
"٧": "7",
"٨": "8",
"٩": "9"]
map.forEach { str = str.replacingOccurrences(of: $0, with: $1) }
return str
}
}
"Hello ١٢٣٤٥٦٧٨٩١٠".replacedArabicDigitsWithEnglish