当我使用xcode编译这两个源时,我收到警告并出现错误:
但是如果你看一下代码在.h文件中定义的方法,就会包含.h文件,重新安排.m文件中的方法也不能解决问题。
此代码有什么问题?
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
答案 0 :(得分:3)
你把它称为C函数,而不是objc消息。试试这种方式:
int should = [self shouldHavePlayed:interval];