What is wrong with displaying currency symbols in iOS

    In June 2016, the IL DE BOTE application developed by us appeared on the App Store . The client asked us to use the font Carisma . It does not apply to system fonts on the iOS platform, which can be understood after trying to find it here . While working on the application, I noted that currency symbols that fall in the range from U + 20B6 (symbol of the Turkish livery) to U + 20BE (symbol of the Georgian lari) and typed in a font that is not among the system ones reduce the application's performance. The ruble symbol is just from the specified range.

    Find the differences:



    Captain gets in touch
    The screen on the right lags. This is noticeable in terms of CPU utilization.

    Let's discuss this.

    We will examine in more detail in which specific situations everything slows down performance. To do this, we break the presentation of the string with the currency symbol into its component parts:

    1. The text can be contained in the following entities: UILabel, UITextView, and UITextField
    2. These entities can use the normal string NSString and the attributed NSAttributedString
    3. For a string, we can get the ruble symbol in one of three ways:

      1. Using HTML:

        NSString *htmlString = @"

        500 ₽

        "; self.string = [[NSAttributedString alloc] initWithData:[htmlString dataUsingEncoding:NSUnicodeStringEncoding] options:@{ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType } documentAttributes:nil error:nil];

      2. Using unicode:

        self.string = [[NSAttributedString alloc] initWithString: @"500 \u20BD"];
        

      3. Using number formatter:

        NSNumberFormatter * numberFormatter = [[NSNumberFormatter alloc] init];
        [numberFormatter setNumberStyle:NSNumberFormatterCurrencyStyle];
        [numberFormatter setCurrencyCode:@"RUB"];
        [numberFormatter setMaximumFractionDigits:0];
        self.string = [[NSAttributedString alloc] initWithString:[numberFormatter stringFromNumber:@500]];
        

    Starting to combine entities, I found that the following combinations reduce performance:

    1. UILabel, string type: attributed, character retrieval methods: 2 or 3
    2. UITextView, string type: any, character retrieval methods: any
    3. UITextField, string type: any, character retrieval methods: any

    The experiment consisted in measuring the load on the processor when scrolling through a list whose elements contained the ruble symbol. The average processor load for a normal state did not exceed 10%, and if there was a problem, the load fluctuated around 30-80%, which can be seen on the gifs.


    In the picture are circled the symbols with which the described problem is observed.

    In order for the application to behave normally, you need to avoid the combinations that I identified, or use the San Francisco system font, as well as fonts from the Helvetica Neue family for currency symbols. But these are the minimum requirements. The true reason for the increase in load remained a mystery to me, and if someone understands the essence of the issue - share your thoughts in the comments.

    Also popular now: