News for hackers. Stuff that matters.
Re:RubyMotion - Ruby for iOS by randomdata on Thursday May 03, 2012 @03:24PM (#3925319)
Isn't that really the difference between something like:

    def animate
      UIView.begin_animation  
      yield  
      UIView.commit_animation
    end

    animate do
      # Do something
    end
and:

    void animate(void (^block)(void))
    {
        [UIView beginAnimation];
        block();
        [UIView commitAnimation];
    }

    animate(^ {
        // Do something
    });
Which to my eye are pretty much exactly the same. In fact, UIView already provides a similar method built into the API.

Anyway, I don't want to diminish what you've accomplished. It's an awesome achievement regardless of the language you choose.

Re:RubyMotion - Ruby for iOS by jballanc on Thursday May 03, 2012 @04:26PM (#3925624)
In RubyMotion, you can do something like:

    def animate(*args)
      UIView.begin_animation
      yield(*args)
      UIView.commit_animation
    end

    animate(myButton, &buttonAnimateBlockFromSomewhereElse)
    animate(myView, myOtherView, &genericAnimateBlockFromSomewhereElseWithTwoArgs)
    animate do
      # Do something locally ignoring args
    end
And, yes, you can do the same thing with Obj-C and some creative casts...but it's nicer in RubyMotion! (ymmv)
Re:RubyMotion - Ruby for iOS by jawngee on Thursday May 03, 2012 @05:14PM (#3925846)
You do it this way:

    [UIView animateWithDuration:1.0f
                         animations:^{
                             self.view.alpha=0.0f; 
                         }];
Not so hard.
Re:RubyMotion - Ruby for iOS by jballanc on Thursday May 03, 2012 @05:28PM (#3925912)
But what if I want to have my animations in one object, and my elements to animate in another? Yes, you can have an Obj-C method return a block, but you're going to have to do some nasty casting if you want to be able to call those blocks with an arbitrary number of arguments. (That, or box everything up in an NSArray, which kinda sucks.)

I think I'll try and write up a demo app to explain what I mean...

Re:RubyMotion - Ruby for iOS by jawngee on Thursday May 03, 2012 @05:38PM (#3925945)
Yes please do because you are making absolutely no sense whatsoever.

I think you are over thinking things.

Re:RubyMotion - Ruby for iOS by randomdata on Thursday May 03, 2012 @11:21PM (#3926856)
He wants to be able to pass any Proc to his method, and any arguments supplied to the method are yielded onto target. A rough Objective-C equivalent would be something like this:

    void animate(void (^block)(va_list), ...)
    {
        va_list args;
        va_start(args, block);
        block(args);
        va_end(args);
    }

    void (^first)(va_list) = ^(va_list args) {
        NSLog(@"%@", va_arg(args, id));
    };

    void (^second)(va_list) = ^(va_list args) {
        NSLog(@"%@", va_arg(args, id));
        NSLog(@"%@", va_arg(args, id));
    };

    animate(first, @"Hello World");
    animate(second, @"Hello", [[NSNumber alloc] initWithInt:10]);
I would like to see the real-world code too. The frameworks in question revolve around Obj-C-isms, so to see something that completely deviates from those patterns will be interesting.
Re:RubyMotion - Ruby for iOS by petercooper on Friday May 04, 2012 @01:06AM (#3927120)
One of the weirdest, but oft repeated, "criticisms" I hear of Ruby is how much "weird punctuation" it uses. A groundless claim compared to most other languages, though, as this snippet illustrates.
Re:RubyMotion - Ruby for iOS by conradev on Thursday May 03, 2012 @03:59PM (#3925471)
> UIView already provides a similar method built into the API.

Yeah, it's actually much, much simpler to do it in Objective-C in this case.

    [UIView animateWithDuration:0.5f animations:^{
        // Do something
    }];
Re:RubyMotion - Ruby for iOS by malyk on Thursday May 03, 2012 @04:21PM (#3925592)
Its

UIView.animateWithDuration(0.5, animations:lambda { //do something })

in RubyMotion. Basically the same.