Reputation: 14571
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
}
Upvotes: 0
Views: 165
Reputation: 62686
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.
Upvotes: 0
Reputation: 5291
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.
Upvotes: 3
Reputation: 974
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
Upvotes: 1