Q:

Objective C: Communicating between classes

I'm writing an iPhone program that has a login view controller that allows the user to login. I have a method I use within that controller that checks the authentication of the username and password. I'm using the keychain to store the username and password, but I'm wondering how I go about communicating outside of the class that the username and password is authentic without duplicating code.
This is probably very simple, but it's getting late and my brain is completely fried...

A:

Good question, and Simon's approach is certainly reasonable.
Another idea would be to create a new class, modeled as a Singleton, called Security and place your authentication method there.  Then any object who wishes to validate the user could simply call into Security.
You can read more on the Singleton pattern here: http://developer.apple.com/iphone/library/documentation/cocoa/conceptual/cocoaFundamentals/CocoaDesignPatterns/CocoaDesignPatterns.html#//apple_ref/doc/uid/TP40002974-CH6-SW6
Hope this helps.
Andrew

