Calculating String Sizes on iPhone in Background Stream

I have several several complicated line size calculations that occur in my application (each of them approaches 500 ms, and occurs when the user views a new “page” in my application (for example, the Weather application). Happens once on page, since the calculation needs to be done only once (and can even be cached for subsequent launches with the same data).

In any case, I still like to block the user interface for this type of work, since for me it screams using threads, but I know that UIKit is not intended for use from other threads. (I know that NSString is not part of UIKit, but string calibration methods are part of UIKitAdditions ...)

So how should I do this? What is the best way to not block the user interface and make it safe?

+3
source share
3 answers

Consider using NSOperation/ NSOperationQueue. There's a tutorial on Cocoa Is My Girlfriend, and Apple has a guide .

+2
source

I always used -sizeWithFontfriends in the background thread to calculate cell heights, etc. It worked perfectly. However, since iOS 6.0 causes an intermittent failure . Hopefully they will be fixed because it is an important performance optimization for calculating UI layouts in the background.

+3
source

, , , UIKit GUI () , .

sizeWithFont: , , .

, iPhone, , , .

+2

Source: https://habr.com/ru/post/1737975/


All Articles