ProMotion Tip of the week

I’d like to welcome Jamon to the Dispatch. He created ProMotion and wrote this week’s ProMotion tip. Let me know what you think, maybe we can persuade him to write a tip every so often.


If you missed the last issue, you can find it here: issue #36.

Happy coding, Todd Werth (@twerth)

Articles, News, New Gems, and Blog Posts


July 24th, 2014 | blog post | by Mirko Stocker
RubyMotion Announces Android Support

July 21st, 2014 | blog post | by Gant Laborde
Custom Controller Transitions in RubyMotion

July 21st, 2014 | screencast | by Jack Watson-Hamblin
MotionInMotion – Episode 34 – Toolbars

July 18th, 2014 | video | by Arkency
Rubymotion App with ProMotion gem

July 18th, 2014 | blog post | by Thomas Mayfield
Setting Up a RubyMotion Project on Travis CI

ProMotion Tip of the Week by Jamon Holmgren


Passing data between screens

When opening and closing screens, you often want to pass data between them. ProMotion has a simple built-in way to do this.

First, define a writable property on your new screen:

class NewScreen < PM::Screen
  attr_accessor :my_data
  # ...
end

Then, when instantiating the new screen, set the data as part of your new call.

open NewScreen.new(my_data: @my_data_here)

Within the NewScreen instance, you’ll now have access to self.my_data which is a strong reference to the object @my_data_here.

When you’re done with a screen and want to close it, you may want to pass some data or information (such as success or failure) back to the parent screen. Just add the info to your close call like this:

# in ChildScreen
def some_method
  close saved: true
end

…and then implement the on_return action in your parent screen.

# in ParentScreen
def on_return(args={})
  puts args[:saved] # => true
end

I use these two features all the time for simple, effective communication between screens.

Hidden Gem by Gant Laborde


Today’s Hidden Gem is a quick Ruby trick. You are likely familiar with Array#uniq.

uniq: provides a unique set of a given array (Also popular in Active Record queries in Rails, under the same concept). So [1, 1, 2, 3, 5].uniq returns [1, 2, 3, 5].

Quick Trick: Combining arrays and preserving the uniqueness happens often. Your first thoughts for combining Array a and b might be (a + b).uniq but did you know you can just use the ruby OR for the same result?

a = [1, 2]
b = [2, 3]
c = [3, 4, 5]

x = a | b | c
# => [1, 2, 3, 4, 5]

RubyMotion News


RubyMotion 2.31

  • The iOS 8.0 and OS X 10.10 versions of the runtime have been recompiled
    with Xcode 6 Beta 4.
  • Fixed a regression where a crash would happen when calling methods with
    variadic arguments.
  • Fixed a bug where Unicode characters outside the BMP of a String object
    would not be properly extracted when passed to an Objective-C API.
  • Fixed a bug where a “not precompiled” error would happen when calling the
    NSURLSessionDownloadTask#cancelByProducingResumeData method.
  • Fixed a bug where a crash would happen when trying to override a method that
    has `MKOverlayRenderer’ arguments (ex. #drawMapRect:zoomScale:inContext:).
  • Fixed a bug where trying to retrieve a value from a Hash object using a
    key wrapped as a WeakRef would not work as expected.
  • [iOS] Fixed a bug where ^C would not terminate the `rake debug=1′ debugging
    session immediately.
  • [iOS] Fixed a bug where custom debug commands (ex. pro, pri) would not
    work in a remote/device debugging session.
  • [iOS] Fixed a bug which user-defined debug commands would not be loaded
    in a remote/device debugging session.

Sponsor


My company InfiniteRed sponsors this newsletter by allowing me the time to work on it every week and hosting everything.

Contact us if you ever need help working on a project, mentoring, or other development services . We specialize in RubyMotion and have an awesome team.

Wat!


Halt and Catch Fire: finally a show about programmers and hardware engineers that is realistic, smart, mature, and highly entertaining (although overly dramatic, of course, no one wants to just watch us type all day).


If you have any tips, blog posts, or want to sponsor this newsletter, please send emails to todd@infinitered.com