I'm new to Objective-C, so I may be way off...
I have this in my 'viewDidLoad' method:
NSArray *myArray;
NSString *cow = @"Cow";
NSString *pig = @"Pig";
NSString *frog = @"Frog";
NSString *sheep = @"Sheep";
myArray = [NSArray arrayWithObjects: cow, pig, frog, sheep, nil];
randomNumber.text = [myArray objectAtIndex: arc4random() % (4)];
I want to make this its own method, so I can get a random animal any time I want...but I need this to happen when the program starts. How do I access a method like this?
I may be way wrong, so I'm open to suggestions, corrections, and anything you think is helpful.
Like this:
- (void)generateAnimal{
NSArray *myArray;
NSString *cow = @"Cow";
NSString *pig = @"Pig";
NSString *frog = @"Frog";
NSString *sheep = @"Sheep";
myArray = [NSArray arrayWithObjects: cow, pig, frog, sheep, nil];
randomNumber.text = [myArray objectAtIndex: arc4random() % (4)];
}
Also:
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
self generateAnimal;
}