I created a class (Foo.m) which I would like to be able to call a method in the controller (MainViewController.m) which instantiated it. How do I do this?

One way you can do this is to create a property in your Foo class that references its creator. You should not retain this reference to avoid circular references, but the code might look like the following

1
2
3
4
- (void) yourControllerClassMethod {
    Foo* f = [[Foo alloc] init];
    [f setOwnder:self];
}

In this case, your Foo class has a property called owner which is set when the Controller class makes a new Foo instance. Now from your Foo class you can call controller methods like this:

1
[[self owner] callSomeControllerMethod];