I have a bunch of drawing code (primitive drawing, mostly bezier path drawing calls) thats stored in a couple of files and the draw code runs to about a few hundred lines. I wanted to know if its possible to read this code from a file and execute it at a particular point in my program (maybe a draw method of a UIView), much like what we do with shaders in openGL 2.0.
I want to be able to use this code to do my drawing but i dont want to copy the drawing code into the UIView class I'm using because it becomes cumbersome to maintain and hardly readable, plus i have many such files!
I know that i can read the contents of a file using existing frameworks, but is there something that will allow me to execute the read contents of the file where i need this drawing code to run?
Any ideas/help is appreciated!
I think you you really want is a category (https://developer.apple.com/library/ios/documentation/cocoa/conceptual/ProgrammingWithObjectiveC/CustomizingExistingClasses/CustomizingExistingClasses.html). You would make a category on UIView for example with all your drawing code in it, then import the category to your view subclasses that need it and call the method where you need it. I'm pretty sure Apple won't let you compile code on an iPhone (shaders are obviously an exception).