Ruby-fy your Objective-C!

J Jon Tara 3 years 6 months ago
1 0 0

If you're writing a Rhodes extension for iOS, you might like to Ruby-fy your Objective-C.

Objective-C/llvm 4.0+ have some new/shorter/more intuitive ways of writing some data structures. It's particularly handy when dealing with arrays and hash. It's much more "Ruby-like".

Documentation/examples/internal extensions (inside Rhodes) are all written the "old way".

I found this short (15min) talk quite helpful:

Objective C for Rubyists | SkillsCast | 10th September 2012

It makes writing hash return values particularly nice:

  if (self.callback) {
    [self.callback setResult: @{
      @"event":        @"didRemoveService",
      @"searching":    @YES,
      @"moreComing":   [NSNumber numberWithBool:moreComing],
      @"serviceName":  [service name]
    }];

vs:

  if (self.callback) {
    NSDictionary* dict = [ NSDictionary dictionaryWithObjectsAndKeys:
      @"didRemoveService",                       @"event",
      [NSNumber numberWithBool:self.searching],  @"searching",
      [NSNumber numberWithBool:self.moreComing], @"moreComing",
      [service name],                            @"serviceName",
      nil ];
    [self.callback setResult:dict];

CONTACT
Can’t find what you’re looking for?