Cory Rylan

My name is , Google Developer Expert, Speaker, Software Developer. Building Design Systems and Web Components.

Follow @coryrylan
Cory Rylan Blog

IOS Journey Load Multi-Threading

Cory Rylan

-

This following example is a small snippet of code I found to create a separate thread from the main thread. This allows you to process information without holding the main thread. For example if a web service is taking a while to load or respond if on the main thread the application may shut down because it believes the application has locked up. This allows the user interface to be usable while loading.

// For asynchronous threading use the following and place code within brackets.
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT,(unsigned long)NULL), ^(void) {
    // Example Thread separate until view loaded then push
    [self.navigationController pushViewController:myViewController animated:YES];
});

// For a separate thread place your method call in the following selector.
[NSThread detachNewThreadSelector: @selector(MyMethod) toTarget:self
withObject:nil];
// To break out of the current thread and process something on the main use the following:
[self performSelectorOnMainThread:@selector(yourMethod) withObject:nil waitUntilDone:YES];
Twitter Facebook LinkedIn Email
 

No spam. Short occasional updates on Web Development articles, videos, and new courses in your inbox.

Related Posts

Cory Rylan Blog

IOS Character Counter

A short code example of how to make a character counter for IOS in Objective C.

Read Article
Cory Rylan Blog

IOS Journey the Observer

A short code example of how to use the observer object for IOS in Objective C.

Read Article
Cory Rylan Blog

IOS Journey Load Animation

A short code example of how to create a load animation for IOS in Objective C.

Read Article