ios - performSelectorInBackground in Swift -


now noticed [nsobject performselectorinbackground] unavailable in swift.

somethings in background in swift, can use
instead of performselectorinbackground?

found dispatch_async(dispatch_get_global_queue(dispatch_queue_priority_background, 0), ^{}), can alternative of performselectorinbackground?

i found dispatch_async(dispatch_get_global_queue(dispatch_queue_priority_background, 0), ^{}), can alternative of performselectorinbackground?

yes.

as matter of fact, there difference.

nsobject -performselectorinbackground:withobject: method spawn new thread using nsthread.

using nsobject spawn thread

in ios , os x v10.5 , later, objects have ability spawn new thread , use execute 1 of methods. performselectorinbackground:withobject: method creates new detached thread , uses specified method entry point new thread. example, if have object (represented variable myobj) , object has method called dosomething want run in background thread, use following code that:

[myobj performselectorinbackground:@selector(dosomething) withobject:nil];

the effect of calling method same if called detachnewthreadselector:totarget:withobject: method of nsthread current object, selector, , parameter object parameters. new thread spawned using default configuration , begins running. inside selector, must configure thread thread. example, need set autorelease pool (if not using garbage collection) , configure thread’s run loop if planned use it. information on how configure new threads, see configuring thread attributes.

by contrast, grand central dispatch, global queue more efficient, more sophisticated.

concurrency , application design

  • they offer automatic , holistic thread pool management.
  • they provide speed of tuned assembly.
  • they more memory efficient (because thread stacks not linger in application memory).

Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -