I want to set a label to string: \"خخخ just bought: Disguise Kit.\" but when I run the test, the label show \".just bought: Disguise Kit خخخ\"?
If the text is not be
Since iOS 10 (and macOS 10.12) String localizedStringWithFormat inserts Unicode isolates around placeholders.
This is a higher level way to format strings with mixed language direction, without manually inserting directional marks.
String.localizedStringWithFormat("%@ just bought: Disguise Kit.", "خخخ")
// "خخخ just bought: Disguise Kit."
Compare to:
String(format: "%@ just bought: Disguise Kit.", "خخخ")
// ".just bought: Disguise Kit خخخ"
To see what localizedStringWithFormat is doing:
let scalars = String.localizedStringWithFormat("%@ just bought: Disguise Kit.", "خخخ")
.unicodeScalars.map { "U+\(String(format: "%04X", $0.value))" }
print(scalars)
// ["U+2068", "U+062E", "U+062E", "U+062E", "U+2069", "U+0020", ...
Where U+2068 is FIRST STRONG ISOLATE, and U+2069 is POP DIRECTIONAL ISOLATE. You can read more about isolates in: https://www.unicode.org/reports/tr9/tr9-41.html#Explicit_Directional_Isolates
This feature was introduced in WWDC 2016 session 232 What's New in International User Interfaces