Last Updated: February 25, 2016
·
1.494K
· 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)
end

def background_method
  print 'Background Method Called!'
end

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' => 'chavez@me.com' }
  self.performSelectorInBackground('background_method:', withObject:details)
end

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

For other methods check the Apple docs