0

So say I have:

MyViewController.h MyViewController.m

I'd like to have: MyViewController.h MyViewController1.m MyViewController2.m (or however many I need)

Kind of like partial classes in .NET, it just makes it easier to organize things... So is there a way to split an implementation up to more than one file? If so how do I do this? and note that my viewcontroller has a .xib associated with it. Thanks

Shai UI
  • 50,568
  • 73
  • 204
  • 309
  • One could say that this is a good hint for too big classes. – Eiko Jan 23 '11 at 18:55
  • I haven't really separated anything to classes, just a bunch of methods inside my viewcontroller(s)... but the implementation is just getting way too long. i wanted to have one implementation for events, and maybe another implementation for everything else like utility methods etc. if you have some other suggestions (instead of splitting) let me know – Shai UI Jan 23 '11 at 18:58
  • The splitting in files is basically the simple way of grouping related things. But the more code and files you create, the harder it is to maintain. And every reference to things in to the other files will become more expensive. I'd try to use this separation as the first hint for new extra classes that handle that specific part (and just that). Small classes and clear responsibilities will pay off. I admit it's easy to forget when writing code. :-) – Eiko Jan 23 '11 at 19:11
  • especially on an iphone where most programs are smaller.. classes get forgotten sometimes, heh. but thanks point taken ;) – Shai UI Jan 23 '11 at 19:17
  • Just curious, but how long is long? (How many lines) – aqua Jan 23 '11 at 21:17
  • See my answer here for an approach -- http://stackoverflow.com/questions/13357775/split-objective-c-code-into-multiple-files/15315895#15315895 – software evolved Mar 09 '13 at 21:49
  • See my answer here for an approach -- http://stackoverflow.com/questions/13357775/split-objective-c-code-into-multiple-files/15315895#15315895 – software evolved Mar 09 '13 at 21:50

2 Answers2

4

You can use categories in Objective-C to split your implementation portion of your class. This allows you to logically split your class's methods into separate files.

Eric Baker
  • 357
  • 4
  • 14
1

In short, yes you can. As long as you can follow your structure and not get confused, I don't see any issue in it.

Erica Sadun follows the same structure in her examples.

Now, when you get into using XIB's, then you start conflicting.

WrightsCS
  • 50,551
  • 22
  • 134
  • 186