0 Replies Latest reply on Mar 25, 2015 12:28 PM by Jon Tara

    Ruby-fy your Objective-C!

    Jon Tara

      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];