|Oct 25, 2010, 06:36 AM||#1|
Using string as #import variable
quick objective-c question:
I have a list of header files. I want to import one of these header files based on a string variable:
exampleString = "example.h"
but '#import exampleString' doesn't work
How do I convert the string in order to let it be recognized as a variable name?
|Oct 26, 2010, 04:51 PM||#4|
Thank you for the replies.
I asked the same question on another forum, and I got the answer that my method isn't possible since #import is interpreted at compilation time, while strings are interpreted later, at run-time. Thus the compilation error. It seems that using #import is taking the wrong approach.
I have a bunch of header files, each containing arrays with 3d vertex points and UV texture coordinates (3d models as OpenGL code, created with Obj2OpenGL if you are familiar with it). But the program only need to use the data from one model at the time - so what would be the best approach, considering the program preferably should run sowewhat efficiently?
|Oct 26, 2010, 05:25 PM||#5|
What do you mean by "the program only need to use the data from one model at the time"?
If what you want is to #import certain header files and to determine this at compile time then you can use a macro, like I showed above. #define the macro either in your pch file or for the -D in your build settings. Then surround the #includes like I showed earlier.
In effect this is the same as commenting out certain includes. This is also the way that one does DEBUG versions of apps.
|Oct 26, 2010, 05:47 PM||#6|
When the largest of these files is compiled, how big is the resulting compiled code and data? Kilobytes? Hundreds of kilobytes? Megabytes?
How efficient does it have to be in order to qualify as "somewhat" efficient?
I'm asking all of this because you're trying to be efficient without having quantified the problem, nor quantified what would be an acceptable solution of the problem.
My first thought is that you should just import all the headers all at once, and not care at all about the size. Unless you have some measured numbers and a problem with size or performance, you're worrying about something that isn't even perceivable yet. Or if it's perceivable you haven't said what the problem is.
My second thought is that compiling models as source isn't a plan that lends itself to long-term or large-scale efficiency. There is a reason that models are often kept as data files to be read when a program runs. Even there, though, one doesn't use the same strategies for programs with dozens of models vs. those with thousands or millions of models.
The question you've asked is how to get your current solution to work, instead of how to solve the actual underlying problem. You should outline the problem you're really trying to solve by using Obj2OpenGL. If it's "load OBJ models and use them in OpenGL", that's a problem that might be solved in many different ways. You've chosen a solution that might not be the best one, but without knowing what the problem really is and its scale, it's difficult to offer advice.
|Thread Tools||Search this Thread|
|thread||Thread Starter||Forum||Replies||Last Post|
|String as equation?||wesg||iPhone/iPad Programming||4||Sep 29, 2010 05:33 PM|
|Using a string as a method argument in Obj C||tw002||Mac Programming||6||Jan 10, 2010 03:15 PM|
|Array as instance variable||RutgerB||iPhone/iPad Programming||1||Apr 2, 2009 03:28 AM|
|String as variable||forrestgrant||Mac Programming||6||Jul 24, 2008 12:58 PM|
All times are GMT -5. The time now is 10:18 AM.