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

Mockup & CodeGen, iPhone & iPad
($9.99)

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

Manu
($0.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum

View Single Post
Old 06-11-2009, 02:08 AM   #4 (permalink)
smasher
Senior Member
iPhone Dev SDK Supporter
 
smasher's Avatar
 
Join Date: Jul 2008
Location: San Mateo, CA (San Fran)
Posts: 3,858
Default

Quote:
Originally Posted by canit210 View Post
thanks that's exactly what i was looking for.

Would that go in the .m file or the .h file?

Depending on which one, would I need to add anything to the other one. (I'm a beginning programmer so please be nice!)

Thank you.
You need to declare variables in the .h file if they're used in more than one method, and you want them to keep their value. They're called instance variables.

Code:
//these would go between the interface brackets
int weightedRandom;
NSString *mathQuestion; //I forgot the asterisk last time
Any code that performs an action (as opposed to just declaring variables) goes in the .m file. If you've already declared the variables in the .h file, then the code changes a little. We don't need to declare the variables again, we can just use them:

Code:
int randomA = arc4random() % 6;
int randomB = arc4random() % 6;

weightedRandom = randomA + randomB;

int randomA = arc4random() % 6;
int randomB = arc4random() % 6;

mathQuestion = [NSString stringWithFormat: @"%d + %d", randomA, randomB];
__________________

Free Games!
smasher is offline   Reply With Quote
 

» Advertisements
» Stats
Members: 158,722
Threads: 89,183
Posts: 380,508
Top Poster: BrianSlick (7,125)
Welcome to our newest member, idny99
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 12:03 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.