D
D
Dmitry Zamula2014-07-04 15:01:12
Objective-C
Dmitry Zamula, 2014-07-04 15:01:12

How to load NSData on another thread?

How to execute the following code in the background so that it does not load the interface?

NSData *data = [NSData dataWithContentsOfURL:url];
    
    _serial.poster = data;

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
mozilla9, 2014-07-04
@mozilla9

dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
       NSData *data = [NSData dataWithContentsOfURL:url];
        
        // если нужно обработать результат в главном потоке
        dispatch_async(dispatch_get_main_queue(), ^{
           _serial.poster = data;
        });

    });

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question