Search code examples
objective-cxcoderight-to-lefthebrewbidi

Xcode LTR and RTL text mixed from database


I had the same problem when I tried implementing the same scenario in a Android studio app here Android studio question and answer

Now I have the same issue in Xcode, I'm using data from a database and displaying it in a textview, whenever a list view item starts with LTR text then the rest of the line displays correct even if there is RTL word in the middel of it. But whenever a item starts with RTL text, it throws the whole item to RTL and not only the RTL word.

Is there any way I can force the view to always stay LTR even if it starts with a RTL word, like the answer marked in the link above?

Bidi codes just gets displayed, as if it doesn't know what to do with the codes. Examples:

I want to display the following:

‘אנא אנא - Ek is, was, sal wees Wie Ek is, was, sal wees.”

But it gets displayed as:

”.Ek is, was, sal wees Wie Ek is, was, sal wees - אנא אנא‘

When the hebrew text is between other normal text its fine like:

‘He says אנא אנא - I am, was, shall be Who I am, was, shall be.”


Solution

  • If someone comes across the question with the same issue I got the following answer. Add this to your viewcontroller after displaying your string from the database :

    [_content appendString:@" \u200E"] ;