Im trying to write some code where the computer creates a random integer between 1 and 12 and I want to be able to compare that number elsewhere in my code. How do I call that number in a method? Im very new to this so any help is appreciated
heres how i called it in the .h
int losingVault
in the .m this how i create the random number
losingVault=rand()%12+2;
how do i call that elsew开发者_Python百科here in my code?
Well, this isn't a lot to go on. It seems like you may need some basic help understanding Objective-C. There are a couple books people like to recommend, Programming in Objective-C by Stephen Kochan is probably the most popular.
So, the way your example code is written, losingVault
will probably have visibility in the entire class in which it was defined. If you look in your .h file, int losingVault;
is probably within an @interface {ClassName}
block. In your .m file, there should be a matching @implementation {ClassName}
block. Anywhere inside that block should be able to access the variable by just calling losingVault
. You could make that variable visible outside of that class in a number of ways.
I hope this helps.
精彩评论