How does multithreading work in Objective-C on iPhone?

I got confused about the concept of “streams” in the development of the iPhone:

  • Why are threads necessary / useful?
  • How to use streams in Objective-C?
+3
source share
4 answers

You need multithreading in object c, because sometimes you need functions / code to run "in the background" (read: in another thread). For example (but not explicitly) you may need to download a large amount of data from the Internet (image or video).

iphone . , . iphone .

objective-c. , , , .

: NSURLConnection [self performSelector:onThread:...]

+6

... () , ... , ... , - ... : 1: 2: (, ..) . , ,

0

The recommended way to implement concurrency is to use queues.

For those who just want to execute a method / block in a separate thread, use this code:

dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
dispatch_async(queue, ^{
   [self longMehtod];
});

read Apple's Concurrency Programming Guide for more information

0
source

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


All Articles