Reputation: 1
Hi i have a function on a class which is like this :
- (Float32)averagePower {
if (![self isListening])
return 0.0;
float tmp = [self levels][0].mAveragePower;
tmp = tmp * 100;
NSLog(@"%f", tmp);
return tmp;
}
i am calling it from viewdidload of another class like this:
SoundSensor *theInstance = [[SoundSensor alloc] init];
[theInstance listen];
Float32 tmp;
[theInstance averagePower:tmp];
now i can call to listen but when calling to averagepower i got warning that it may not respond and the function is crashing in simulation. what i do wrong ?
thanks a lot.
Upvotes: 0
Views: 167
Reputation: 28572
You are calling the method with a parameter:
[theInstance averagePower:tmp];
but it does not have any parameters in its definition:
- (Float32)averagePower {
// ...
}
This is causing the crash. If you are trying to assign the return value of the method to the tmp
variable, you should do this:
Float32 tmp = [theInstance averagePower];
To get rid of the warning make sure you declare this method in the interface block of the corresponding class (the h file).
Upvotes: 3
Reputation: 7982
You are trying to pass a variable to a function that accepts no parameters.
What I expect you meant to do is this:
Float32 tmp = [theInstance averagePower];
Upvotes: 1