bartvd
bartvd

Reputation: 3

Objective C error Thread stops running

I am trying to make my code run, but it always stops. Can someone of you help me solve the problem. For some reason it wont accept this.

-(Animal *) getAnimalAt:(int)input {
    //NSLog(@"show input %ld", input);
    Animal *ani = [animals objectAtIndex:input];
    return ani;
}

I call this method in my main by :

for(int i=0;i< count;i++){
        Animal *ani = [farm getAnimalAt:i];
        NSLog(@"ani :  %@",[ani makeSound]);
        NSLog(@"ani :  %@",[ani doFly]);
    }

If you need any more info or code please ask.

Also do any of you have found a good tutorial? I cant seem to find one? Or a site like codingbat would be very helpfull.

Upvotes: 0

Views: 62

Answers (1)

iain
iain

Reputation: 5683

If animals is just an NSArray you could remove the getAnimalAt: method and just use the NSArray. Then you could do something like:

for (Animal *ani in animals) {
    NSLog(@"ani :  %@", [ani makeSound]);
    NSLog(@"ani :  %@", [ani doFly]);
}

which will prevent any problems with count being greater than the number of elements in animals

Upvotes: 1

Related Questions