TOP KEK
TOP KEK

Reputation: 2641

Execute task in background

In my app after user press start button I execute some code in for cycle. How to keep application responsible for user interaction during this? In C# there is BackgroundWorker class, is there anything similar in IOS?

Upvotes: 0

Views: 1015

Answers (2)

Justin Boo
Justin Boo

Reputation: 10198

You can use selector like this:

[self performSelectorInBackground:@selector(yourForCycle:) withObject:nil];


-(void)yourForCycle:(id)sender {

    //Your for cycle...
}

Upvotes: 1

Omar Abdelhafith
Omar Abdelhafith

Reputation: 21221

use gcd like following

dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
dispatch_async(queue, ^  {  
   //Put your heavy code here it will not block the user interface
});

Upvotes: 2

Related Questions