Quote:
Originally Posted by baja_yu
Create a property or a pure ivar for the number and use that to get the generated value, don't make a new one every time.
|
Hi baja,
I appreciate your response but am still running into a bit of trouble. I read up a bit more on properties to make sure I understood them correctly, but as it turns out, I don't think I do. In my .h class I set the randoms to NSUIntegers and declared them as properties as seen below:
Code:
NSUInteger *randomTall;
NSUInteger *randomWide;
NSUInteger *randomYPosn;
NSUInteger *randomXPosn;
@property (nonatomic, retain) NSUInteger *randomTall;
@property (nonatomic, retain) NSUInteger *randomWide;
@property (nonatomic, retain) NSUInteger *randomYPosn;
@property (nonatomic, retain) NSUInteger *randomXPosn;
In the .m file I synthesized the variables and used the following implementation to actually set the values in one of my methods:
Code:
randomTall = 50 + arc4random() % 197];
randomYPosn = 44 + arc4random() % (290-44-randomTall);
randomWide = 50 + arc4random() % 431;
randomXPosn = arc4random() % (480-randomWide);
In the .h file I am getting an error stating that the 4 properties with 'retain' attribute must be of object type... Should I change this to assign or is there a conflict between with using the NSUInteger type?
I am also getting an error in my .m file that says I am invalidly using the "- operand" because I'm using it with an int and NSUInteger type. Obviously conflicting.
One other big conflict I am seeing as well is that I am later using this random number to set the frame of a rectangle and because CGRectMake doesn't take an NSUInteger it's throwing an error here as well.
I think the biggest confusion is that I am not using the right data type and/or I may not be setting/assigning the property correctly. Once again, I assure that I did read some of the property tutorials posted here on iphoneDevSDK and other places online and made changes accordingly but I'm thinking a may still be pretty far off base.
Thanks so much for your help.
__________________
Ping Ping: An arcade-style game featuring accelerometer-based controls, an achievement system, and local high score board.
Ping Ping
AddTap: Educational application that puts a unique spin on simple addition problems, adding speed and accuracy to the equation.
AddTap