views:

65

answers:

1

I have a class along the lines of:

@interface Foo : NSObject {
    NSMutableArray *bar;
}

Foo isn't a controller -- it's responsible for some other logic that I want encapsulated.

I'd like to have a label display the size of bar. If it was a value in a controller, I could simply make it an IBOutlet, connect it in IB, and everything would just work.

Can I do that with bar above?

A: 

If you're using that class to encapsulate certain functionality, don't use it to update the UI too. Rather have an instance of class Foo in your view controller and let your view controller update the label's value with the value of bar's size. You should make bar available via an accessor

nduplessis
I have an instance in the controller class, but I'm not sure how to go from there to "let the view controller update the label's value..."
Bill
I would imagine there are two ways of doing it. Either create a delegate for your Foo class and send a message to the delegate each time you modify the array or use key value observing to observe changes to the array
nduplessis
Bill