When I compile these two sources with xcode I get a warning and an error:
- Implicit declaration of function ‘shouldHavePlayed’. (at the line with the comment)
- an error while linking.
But if you look at the code the method is defined in the .h file, the .h file is included and rearranging the methods in the .m file doesn’t solve the problem either.
What is wrong with this code?
TimerItem.h:
#import <Foundation/Foundation.h>
@interface TimerItem : NSObject {
BOOL enabled;
NSTimeInterval startTime;
NSTimeInterval repeatTime;
int sound;
int played;
}
- (void) play;
- (void) resetPlays;
- (BOOL) ShouldPlay : (NSTimeInterval) interval;
- (int) shouldHavePlayed : (NSTimeInterval) interval;
@end
TimerItem.m:
#import "TimerItem.h"
@implementation TimerItem
-(BOOL) ShouldPlay : (NSTimeInterval) interval {
int should = shouldHavePlayed(interval);//
return (should > played);
}
-(void) play {
played++;
}
-(void) resetPlays {
played = 0;
}
-(int) shouldHavePlayed : (NSTimeInterval) interval
{
if (interval < startTime) {
return 0;
}
else {
if (repeatTime > 0.0) {
return (int) floor((interval-startTime)/repeatTime)+1;
}
else {
return 1;
}
}
}
@end
you are calling it like a C function, not an objc message. try it this way instead: