clearsightstudio/ProMotion — pull request #93 by danreedy (2013-05-24 20:20:54+00:00)
Title: NSNotificationCenter Integration :: Concept, Please Review!

I am using NSNotificationCenter to observe changes throughout my app and wanted a tighter integration with ProMotion screens. This is working in my app, but I have not testing it widely and I am certain there are some short comings. Please take a moment to review and provide any feedback!

### What does it do?

The `Promotion::Screen` class has been extended to allow for observers to be defined. When `on_create` is called the observers are declared. You can use NSNotificationCenter to explicitly post to an observer, but since this is tightly coupled with `close` I have added a method call to that fires off any notifications passed with `close`.

### What's it look like?

You start by adding observers to a `Screen`

```
class UserScreen < PM::Screen
attr_accessor :user
observe User::CHANGED, :update_biography

def update_biography(notification)
# .. do something, such as: ..
self.user = notification.object
end
end
```

Then, you tell a screen that is closing to notify an observer with that name

```
class LoginScreen < PM::Screen
def login
@user = User.login!
# .. login code, and then ..
close notify: { name: User::CHANGED, object: @user }
end
end
```
---
I'm not convinced this is the cleanest implementation, but so far it has worked as expected in the app I've built. I'm new to both iOS development and RubyMotion, so if I'm missing the point of something or have overlooked something just let me know!