Organization and Structure of iPhone/iPad Projects
I've been developing iPhone apps for a while now and something that's always peeved me is that I haven't found a comprehensive way to organize my application files.
I know that an iPhone project is technically MVC, but it seems like most everything I do is in a ViewController. I notice that as a project goes on, my ViewControllers continue to get more and more bloated and I can't help but think that there has to be a better way than this. I also do some ruby on rails and I like the fact that on th开发者_如何学运维at platform there is such a clear separation of concerns and an established way to organize an application.
Has anyone discovered a way that they especially fond of for organizing the application? Also how do cut back on the view controller bloat?
I agree, just about everything seems to land in view controller classes, and they get unwieldy in a hurry. There are several things you could try:
- Create separate classes for delegates, if they don't actually need to be part of the view controller;
- Put delegate method implementations into a category, as described here;
- Factor out any methods that don't actually interact with the rest of the view controller, and put them in separate classes
- Use blocks for asynchronous callbacks when they make sense, because they are often less verbose than explicit callback methods;
- Or even just organize your methods carefully and use
#pragma mark
so Xcode can help you navigate through the file.
This isn't an exhaustive list, of course, and others may have better suggestions.
精彩评论