Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 11-18-2011, 11:03 AM   #1 (permalink)
Registered Member
 
Join Date: Sep 2010
Posts: 194
mavrik5150 is on a distinguished road
Default Choose different enum for different Devices

Hello everyone, got a question here since I'm stumped on trying to get it setup. I wanted to see if there's a way to choose a different set of enums when using a different device. Basically what I have is some object movement speeds defined in a "type enum" and if the device is an iPad I want those values doubled since the larger screen has more room. I tried using the UIUserInterfaceIdiom option to check if it's an iPad or not, but I can't seem to figure out how to use those in a if statement to choose a different typedef enum list. I don't know what code to supply, so if you want me to show what I've tried here's what I have below:

Code:
 
//Setup Movement Speeds
typedef enum { 
#if UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone  
    NormalSpeed = 2, 
    SlowSpeed = 1,
    FastSpeed = 4,
    ConfusedSpeed = -2
#elif UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad
    NormalSpeed = 4, 
    SlowSpeed = 2,
    FastSpeed = 8,
    ConfusedSpeed = -4
#endif
} MovementSpeeds;
This code above doesn't work but is essentially what I'm trying to achieve. I get a "Token [ is not valid in preprocessor expressions" which doesn't really make sense since I'm not using a bracket anywhere but I'm sure it's probably something else that I'm trying to do incorrectly but can't figure out how to fix this. I wanted to do it this way so I don't have to constantly check for device type when changing speeds throughout the level.
mavrik5150 is offline   Reply With Quote
Old 11-21-2011, 12:15 PM   #2 (permalink)
Registered Member
 
Join Date: Sep 2010
Posts: 194
mavrik5150 is on a distinguished road
Default

Bump, I know this may be a painfully simple answer I just need someone to slap me in the back of the head and let me know where I'm going wrong here. Thanks.
mavrik5150 is offline   Reply With Quote
Old 11-21-2011, 12:53 PM   #3 (permalink)
Registered Member
 
Join Date: Jan 2011
Posts: 144
iAppDev is on a distinguished road
Default

are you putting it in the ViewDidLoad section?
so when the app loads, your desired enum for desired device loads.
iAppDev is offline   Reply With Quote
Old 11-21-2011, 12:54 PM   #4 (permalink)
Registered Member
 
Join Date: Jan 2011
Posts: 144
iAppDev is on a distinguished road
Default

here's a good tut that might get you on the right path

http://www.youtube.com/watch?v=n7aNHzPPmzo
iAppDev is offline   Reply With Quote
Old 11-22-2011, 11:25 PM   #5 (permalink)
Registered Member
 
Join Date: Sep 2010
Posts: 194
mavrik5150 is on a distinguished road
Default

Thanks iApp, I did see that video before but was trying to see if there was any other way besides doing that in viewdidload (or in my case the init method since this is a Cocos2d game). I was declaring this right after the @implementation along with a few other enum's that will be used throughout the code so I thought there was a way to do an if statement to a enum but maybe not. Looks like I may just have to declare all the values as ivars and then do the check in my init for now. Thanks again.
mavrik5150 is offline   Reply With Quote
Old 11-23-2011, 05:05 AM   #6 (permalink)
Registered Member
 
Join Date: Nov 2009
Location: Helsinki
Posts: 304
fiftysixty is on a distinguished road
Default

Quote:
Originally Posted by mavrik5150 View Post
Thanks iApp, I did see that video before but was trying to see if there was any other way besides doing that in viewdidload (or in my case the init method since this is a Cocos2d game). I was declaring this right after the @implementation along with a few other enum's that will be used throughout the code so I thought there was a way to do an if statement to a enum but maybe not. Looks like I may just have to declare all the values as ivars and then do the check in my init for now. Thanks again.
The main problem you have now is that you're using preprocessor statements, which by definition happen before the code is compiled. It is impossible to do it the way you're trying: your compiled executable will only contain one set of enums no matter what device it's run on.

Regarding the error message you get, the UI_USER_INTERFACE_IDIOM() is a macro that the preprocessor will expand into actual code to be compiled. So you're basically mixing preprocessor if statements with compiled code, and they don't mix too well.
fiftysixty is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
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
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 400
18 members and 382 guests
7twenty7, Alex-alex, Apptronics RBC, baja_yu, chiataytuday, dre, e2applets, gwelmarten, ipodphone, jeroenkeij, jleannex55, matador1978, mbadegree, n00b, pbart, QuantumDoja, Retouchable, usernametaken
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,676
Threads: 94,125
Posts: 402,910
Top Poster: BrianSlick (7,990)
Welcome to our newest member, jleannex55
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 06:26 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0