Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Oct 25, 2010, 05:36 AM   #1
Rendse
macrumors newbie
 
Join Date: Oct 2010
Using string as #import variable

Hi all,

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?

Thanks
Rendse is offline   0 Reply With Quote
Old Oct 25, 2010, 09:47 AM   #2
PhoneyDeveloper
macrumors 68020
 
PhoneyDeveloper's Avatar
 
Join Date: Sep 2008
You can't do that directly. You can conditionalize your imports with macros.

Code:
#if SOMECONDITION
#import "x.h"
#else
#import "y.h"
#endif
PhoneyDeveloper is offline   0 Reply With Quote
Old Oct 25, 2010, 10:35 AM   #3
dejo
Demi-God (Moderator)
 
dejo's Avatar
 
Join Date: Sep 2004
Location: Colorado
My question is: why do you think you need to do this?
__________________
dejo is online now   0 Reply With Quote
Old Oct 26, 2010, 03:51 PM   #4
Rendse
Thread Starter
macrumors newbie
 
Join Date: Oct 2010
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?
Rendse is offline   0 Reply With Quote
Old Oct 26, 2010, 04:25 PM   #5
PhoneyDeveloper
macrumors 68020
 
PhoneyDeveloper's Avatar
 
Join Date: Sep 2008
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.
PhoneyDeveloper is offline   0 Reply With Quote
Old Oct 26, 2010, 04:47 PM   #6
chown33
macrumors 601
 
Join Date: Aug 2009
Quote:
Originally Posted by Rendse View Post
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?
How many is "a bunch"? Dozens? Hundreds? Thousands?

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.
chown33 is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
thread Thread Starter Forum Replies Last Post
String as equation? wesg iPhone/iPad Programming 4 Sep 29, 2010 04:33 PM
Using a string as a method argument in Obj C tw002 Mac Programming 6 Jan 10, 2010 02:15 PM
Array as instance variable RutgerB iPhone/iPad Programming 1 Apr 2, 2009 02:28 AM
String as variable forrestgrant Mac Programming 6 Jul 24, 2008 11:58 AM


All times are GMT -5. The time now is 09:40 AM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

Privacy / DMCA contact / Affiliate and FTC Disclosure
Copyright 2002-2013, MacRumors.com, LLC