Skip to content

Instantly share code, notes, and snippets.

@zekus
Last active August 29, 2015 14:01
Show Gist options
  • Save zekus/11559164 to your computer and use it in GitHub Desktop.
Save zekus/11559164 to your computer and use it in GitHub Desktop.
class AppDelegate
include BW::KVO
attr_accessor :user
def application(application, didFinishLaunchingWithOptions:launchOptions)
@window = UIWindow.alloc.initWithFrame(UIScreen.mainScreen.applicationFrame)
@window.makeKeyAndVisible
@name_label = UILabel.alloc.initWithFrame(CGRectMake(0, 0, 100, 30))
@window.addSubview(@name_label)
@email_label = UILabel.alloc.initWithFrame([[0, @name_label.frame.size.height + 10], @name_label.frame.size])
@window.addSubview(@email_label)
@id_label = UILabel.alloc.initWithFrame([[0, @email_label.frame.origin.y + @email_label.frame.size.height + 10], @name_label.frame.size])
@window.addSubview(@id_label)
self.user = User.new
["name", "id", "email"].each do |prop|
observe(self.user, prop) do |old_value, new_value|
instance_variable_get("@#{prop}_label").text = new_value
end
end
true
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment