rubymotion-community / sugarcube

Some sugar for your cocoa. RubyMotion helpers.
Other
422 stars 66 forks source link

alert() method? #4

Closed beakr closed 12 years ago

beakr commented 12 years ago

A really nice helper would be an alert() method, so users wouldn't have to do a million UIAlertViews:

alert 'Task completed' # alert with just the title
alert 'Task completed', with_text: 'The task you have created has been completed successfully.'
alert 'Task completed', with_cancel_button: 'Woohoo!' # Assign the cancel button

# And a lot more options in the actual UIAlertView...
colinta commented 12 years ago

I considered something like this, and BubbleWrap has this syntax, and it works well. sugarcube has a certain style to it, which is based on adding methods to built-in classes. It turns some operations on their head, so this might look like this:

'Task completed'.alert

which I'm not sure I'm a fan of...

colinta commented 12 years ago

This has been added as a class method on UIAlertView.

UIAlertView.alert "I mean, is this cool?", buttons: %w[No! Sure! Hmmmm]
  message: "No going back now",
  cancel: { self.cancel },
  success: { |pressed| self.proceed if pressed == "Sure!" }