During our trip in Tokyo last month, I and my wife attended TOKYO Rails #19 at COOKPAD, and that is fantastic.
While I don’t actually coding Rails lately, I’m lucky to met a few iOS developers and exchanged a bit, such as introducing もじバトル, SplitCam and EverClip, and see some interesting in house app as well as a creative camera app Cobypic.
And oh, the event venue COOKPAD office is super cool. Their guys kindly made us a fantastic meal. Sorry that I can only bring you a few pictures:
I can’t made it to their iOS meetup… maybe next time!
When using RubyMotion, just like many other new technologies or frameworks, I found gotchas and scratch my head over them.
I’m writing them down in case I might forget them. I hope this may help you or give you ideas on daily issues you might face when using RubyMotion.
When class is not class
Try to convert following Objective-C code into RubyMotion code:
That is wired, but it is not that wired if we think again.
In Objective-C, there is a “+class” class method in NSObject. As its name suggested, it return the class object of the specifing class. For example, [UIView class] return UIView class object.
In Ruby, there is a “#class” instance method in Object. When you called this on an instance of object, it return the class of that object. For example, my_view.class return UIView if my_view is an instance of UIView. Note there are no class method “::class” on Object on Ruby. Why you can still call something like “Time.class” in ruby? It is because any class in Ruby is actually instance of Class.
This explain why MyCell.class in RubyMotion is different from [MyCell class] in Objective-C. Instead of returning class “MyCell”, MyCell.class returning the class of MyCell class.
P.S. If you use JRuby and msgpack-jruby, beware another issue that, msgpack-jruby
behave differently than the MRI version. It will not use default_external
encoding, but you will need to explicitly specify the encoding during unpack. (As
To add a gem to your RubyMotion project, instead of using rubygems to require source files in runtime, you
require it in project Rakefile.
Inside the source file being required, instead of require other files normally you would in rubygems, use
Motion::Project::App.setup to add sources to your motion project:
unlessdefined?(Motion::Project::Config)raise"This file must be required within a RubyMotion project Rakefile."endMotion::Project::App.setupdo|app|Dir.glob(File.join(File.dirname(__FILE__),'nano_store/*.rb')).eachdo|file|app.files.unshift(file)endend