views:

28

answers:

1

I have written a few apps for the iphone now, but they are all written in what I consider to be a lazy, unstructured way.

I have started a new project and have created several Objective-C classes (subclass of NSObject). the problem I have is getting the logic correct in my head. My structure is as follows

viewController.h
viewController.m
plotPoints.h
plotPoints.m
handleFeeds.h
handleFeeds.m

So the main file is the view controller and I include in it's header file the other classes. My problem is that in the other class files, eg plotPoints.m - if I try to refer to a variable I set in the view controller, it says it's not set. I have included the viewcontroller in the plotPoints.h file - but still it doesnt work.

what is best practice for separating code in this way? In this example, I have webservice feeds which I want to handle in one class, then process those results in another and handle the main UI in the view controller.

Thanks for any information.

A: 

I say the Controller shouldn't be referenced by your - as I understand - external classes (plotPoints and handleFeeds, by the way these should definitely begin with an uppercase character).

Actually, it should be the exact opposite, your viewController should be using methods and properties of your external classes. PlotPointsand HandleFeeds should not have to refer to instance variables of your Controller, let it pass them as arguments for you methods instead.

Luzal
so in my view controller, I should include the external classes. these classes then contain functions which I call from the view controller. So if I had a mapview in the view controller, where do I declare the iboutlet for that? Currently I have it in the viewcontroller.h file. I tried declaring it in the plotpoints.h but I cannot see it in interface builder. thanks for your reply.
Matt Facer
I see.Maybe you can try to add an IBOutlet to your mapview in another class, but if you do that you may have to add an instance of your helper class in your .xib (by dragging it from the library inside the "YourFile.xib" window). Then you will have to add an outlet in your ViewController to your helper class. Is this clear enough ?
Luzal