Remove AlamofireImage responseImage from main thread

169 views Asked by At

Simply speaking i'm attempting to download an image on a server using AlamofireImage and it appears that the DataRequest extension responsible for this returns the content on the main thread.

This is problematic because it does inevitably lock the UI while it continues to process.

See the attached image, the breakpoint halts the execution of the main thread (on the left)

Response on main thread

How can I migrate this DataRequest to use an OperationQueue that's not main?

1

There are 1 answers

0
timaktimak On BEST ANSWER

I added an optional queue parameter to the responseImage function so that an arbitrary DispatchQueue could be used to run completionHandler on. enter image description here

Here is the fork:

pod 'AlamofireImage', :git => 'https://github.com/timaktimak/AlamofireImage.git', :branch => 'master'

Edit: it was merged in, so AlamofireImage now has the functionality of calling the completion block on a custom DispatchQueue.

Hope it helps!