I am trying to set the textAlignment on the base of text direction if my textView has Text (Right to left like Arabic)  direction then i want to set the textAlignment NSTextAlignmentRight else my alignment will be NSTextAlignmentLeft. Now the issue is i know how to check the text direction at the time of input in UITextView but once we get the text in UITextView then how we can check it. below is my screenshot and code

 if ([self.txtOutputTranslator baseWritingDirectionForPosition:[self.txtOutputTranslator beginningOfDocument] inDirection:UITextStorageDirectionForward] == UITextWritingDirectionLeftToRight)
{
    self.txtOutputTranslator.textAlignment=NSTextAlignmentLeft;
}
else
{
    self.txtOutputTranslator.textAlignment=NSTextAlignmentRight;
}
As my code show that i am checking the text Direction once i get the output text  but it always running the else condition because i have set the UITextView alignment to Right in properties.any suggestion will be appreciated.Thanks in advance.