What sections are your favorite?

Hey readers, every week in the Dispatch I have a variety of sections such as RubyMotion App of the Week. I’m constantly adding new ones, like this week’s Poll of the Week. Let me know what your favorite sections are, either email me attodd@infinitered.com or tweet at me a @twerth

Help out the community by answering questions on stackoverflow or send me your tips and I’ll add them to next week’s Dispatch.

Happy coding, Todd Werth (@twerth)

Poll of the Week


 

What editor or IDE do you use when developing in RubyMotion?

Results from last poll “snake_case or camelCase?”
Total votes: 47
snake_case: 80.85%
camelCase: 19.15%

Articles, News, and Blog Posts


This week

12/17/2013 – “Read without the wrapper gem Data Model that you created in Xcode when using CoreData in RubyMotion” by なかむら, in Japanese, translate it in Chrome

12/16/2013 – “RubyMotion Getting Started in RubyMine” by Kawasaki Makoto, in Japanese, translate it in Chrome

12/15/2013 – “UnderOS iOS app in 10 minutes” [github] by Nikolay Nemshilov

12/15/2013 – “A Color Inspector in RubyMotion” by Hwee-Boon Yar

12/14/2013 – “Building a custom user interface for your Mac OS X status bar app in RubyMotion” by Elliott Draper

12/14/2013 – “issue_block_given, showing an issue in RubyMotion” by Jamon Holmgren

12/13/2013 – “Texties app released” by Mark Rickert

12/12/2013 – “I realize the acceptance test in the seventh times RubyMotion × Calabash” by Satoshi Ebisawa, in Japanese, translate it in Chrome

12/12/2013 – “RubyMotion – navigation tabs” by Nicolas Cavigneaux, in French, translate it in Chrome

12/11/2013 – “The Secret Life of App.alert()” by Jack Watson-Hamblin

12/11/2013 – “motion-bindable” by Nathan Kot

12/10/2013 – “Symbolicating RubyMotion Crash Logs” by Daniel Ramteke

12/9/2013 – “Working around RubyMotion’s Memory Management Limitations” byJustin DeWind

In case you missed it

10/17/2013 – “Using LLDB to debug a RubyMotion app” by Paul Sturgess

RubyMotion News


 

RubyMotion version 2.17 released

  • Added the `Proc#weak!’ method which transforms the strong reference to the block `self’ variable into a weak reference. Once the `self’ variable is weakly referenced there is no coming back to a strong reference. This method can be used to break cyclic references that the cycle detector is not able to handle yet.
  • Defined implementations of NSObject methods, such as `conformsToProtocol:’, that take Ruby semantics into account on all classes created by RubyMotion.
  • Fixed a bug in compiler where boxed types would not be properly registered if a structure was only used for a pointer.
  • Fixed the dispatcher to let methods expecting a structure of type A accept a structure of type B who has the exact same fields signature, as in C (ex. MKCoordinateRegion and CGRect).
  • Added support for dynamic name directory in project templates. Thanks to Toshiwo for the patch (pull request #144).
  • Fixed a bug in NSArray#{take,drop} where nil could be returned instead of an empty Array object in certain cases.
  • Fixed a bug where NSDate objects would be wrongly converted to Time objects.
  • Fixed a bug where certain structures of the same signatures could not be used. (Ex. NSRect and CGRect in a 64-bit OS X app)
  • Improved Range.new performance. 20% faster.
  • Improved Array performance where finalizes object and expands internal memory. 15% faster.
  • Fixed bugs where ARC’s rules related to method names starting with `new` or containing `copy` or `Copy` where not being followed. This lead to objects returned from Objective-C methods that matched these rules not being autoreleased and objects returned from Ruby to Objective-C not being retained.
  • Fixed the runtime to prefix certain kernel symbols we export (ex. selCopy) in order to avoid clashes at link time with certain 3rd-party libraries.
  • Fixed a bug in in the build system where duplicated entries in the app.resource_dirs array would mess up the resource-copying process.
  • Fixed a bug where nested WeakRef objects (WeakRef.new(WeakRef.new(…))) would not be properly resolved at dispatch time.
  • Fixed a bug in {NSObject,Boxed}#== with a WeakRef object operand where said operand would not be resolved.
  • Fixed a compiler bug where `not precompiled’ errors when it uses structure of GLKit framework.
  • [iOS] Fix various bugs in the UI test helpers, like `tap`.
  • [OSX] Fixed #eval to honor the self binding when evaluating the string.
  • [OSX] Introduced the `app.codesign_for_release’ variable, which controls whether code-signing should occur during `rake build:release’. The default value for this variable is `true’

I’m happy to see the two WeakRef bugs Ken and I submitted were fixed within a week. On the flip-side they existed in the first place.

RubyMotion Tips


Beginner’s Tip

Dates inherit NSDate, strings inherit NSMutableString (which inherits NSString), and arrays inherit NSMutableArray (which inherits NSArray).

This is useful because you get all the normal Ruby string stuff, but you also get the NSMutableString and NSString stuff. There are some cool things in there, check out the docs (and use Dash for your docs)

Here is a cool example, NSArray has the pathsMatchingExtensions method:

(main)> [ '/foo/bar/hello.txt', 'report.pdf', '/user/me/resume.doc' ].pathsMatchingExtensions([ 'txt', 'doc' ])
 => ["/foo/bar/hello.txt", "/user/me/resume.doc"]
(main)>

Advanced Tips

A hack to get a strong ref from a weak ref:

my_strong_var = my_weak_var.tag{}

Let me know if there is a better way to do this, I really am curious. I’ll be adding a utility method to RMQ that does this.

EXC_BAD_ACCESS By Ken Miller (@seriousken)
If you are getting crashes you can’t explain, especially EXC_BAD_ACCESS, you may be trying to call a method on a released object.  This can happen especially if you’re doing something subtly wrong with a WeakRef.  There’s a secret debugging environment variable you can set called NSZombieEnabled, which will keep the released object around instead of freeing it, and then warn you when a method gets called.  To use it just append “NSZombieEnabled=YES” after your normal rake commands.  See here and here for more information.

rake debug=1 NSZombieEnabled=YES MallocStackLogging=1

RubyMotion App of the Week


Updated 11/29/2013 – Bandcamp
“The Bandcamp Listening App for Fans gives you unlimited streaming access to your Bandcamp music collection, plus easy access to our radio show, the Bandcamp Weekly. ”

Article over at RubyMotion’s blog

RMQ Tips


What is RubyMotionQuery (RMQ) you ask? Check out this video or this site

FYI, v0.5 is still in beta, but should be sent out as release/gem this week. I’m having a few WeakRef issues. I started playing around with the new frame system for v0.6. It’s going to be slick.

Gesture tip:

RMQ combines events and gestures (I chose to just call them events). If you need the recognizer after your gesture has fired, you can retrieve it from the rmq event object (which contains a bunch of stuff), like so:

rmq(your_view).on(:tap) do |sender, rmq_event|
  gesture_recognizer = rmq_event.recognizer
  # Do stuff here
end

You can also set the options of the gesture when you create the rmq event, like so:

rmq(your_view).on(:tap, fingers_required: 2, maximum_number_of_touches: 3) do |s|
  # Do stuff
end