0

I have a class that loads the drawing code for a bunch of graphics. It goes something sort of like this:

if (type == RabbitGraphic)
{
     //a whole bunch of drawing code gets loaded into an object
}
else if (type == FrogGraphic)...

This file is getting quite long with the more graphics I've added to it and the compilation / loading the file are taking a while. I'm wondering, is there a way I can split these graphics into separate files without having to create a new object? IE is there some mechanism I can do like:

if (type == RabbitGraphic)
{
      load file that has rabbit graphic code
}
Ser Pounce
  • 14,196
  • 18
  • 84
  • 169
  • You could use `#include`, but this probably won't help compilation times any. Why do you not want to create a new drawing class for each type of graphic? That's what classes are *for*. – Sophistifunk Oct 25 '12 at 04:46
  • 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:48

3 Answers3

3

Why are you trying to avoid creating a new object? It sounds to me like more OOP is what is called for here. You should have individual classes that implement the various bits of graphics code specific to each type, optionally with a parent class that implements common functionality.

Nathanial Woolls
  • 5,231
  • 24
  • 32
1

I would place all of your graphics in a DB and load them through the network - much easier to maintain and doesn't impact the ever so precious disk space on mobile devices. Check out the heroku tutorial and run with it. At the end of the day, its a great design for app stack to client layers and its free to develop!

Images and Apps in iOS/ any endpoint that can do HTTP

roguequery
  • 964
  • 13
  • 28
0

I think you might be looking for objective-c categories. The gist of it is you can declare interface and implementations like this:

@interface MyMainClass
@end

Then in another file, usually called MyMainClass+OtherStuff.h

@interface MyMainClass (OtherStuff)
@end

Similarly with @implementation's. The syntax allows you to do just what you're looking for: to group related methods into separate modules without spanning classes.

danh
  • 62,181
  • 10
  • 95
  • 136