Last Updated: February 25, 2016
· mtchavez

RubyMotion background threads

Should you need to perform some background tasks in your Ruby Motion app try the following:

# Call your 'background_method'
def some_method
  self.performSelectorInBackground('background_method:', withObject:nil)

def background_method
  print 'Background Method Called!'

It is as easy as that. If you need even more flexibility and find yourself wanting to give your background method something to work with you can pass objects to it instead of passing nil to withObject

# Use withObject to pass objects into background_method
def some_method
  details = {'username' => 'Chavez', 'email' => '' }
  self.performSelectorInBackground('background_method:', withObject:details)

def background_method(details)
  print "My details #{details}"

For other methods check the Apple docs