Advertise Books Events Forum News Social Networking Support Us

sdkIQ for iPhone
($4.99)

Shape Up
($0.99)

Your First iPhone App
($1.99)

iVidCam Free
(free)

Kid Art
($0.99)

iPUBQUIZ
(£1.19)

ArtStudio
($3.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum

View Single Post
Old 06-11-2009, 01: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: 2,565
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];
__________________
smasher is offline   Reply With Quote
 
Enter the iPhone App Challenge!  Win $500!
» Advertisements
» Stats
Members: 24,163
Threads: 38,935
Posts: 170,827
Top Poster: smasher (2,565)
Welcome to our newest member, iphonenikku
Powered by vBadvanced CMPS v3.1.0

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