#import "movie.h"
int main (int argc, const char * argv[])
{
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
// insert code here...
movie *obj = [[movie alloc]init];
[obj findinterestofnum1:(int)200 num2:(int)4 num3:(int)5];
SEL suf = @selector(findinterestofnum1: num2:num3:);
BOOL sul = [obj respondsToSelector:suf];
if(sul)
{
NSLog(@"It is implememted");
}
else
{
NSLog(@" It is not implemented");
}
NSLog(@"Hello, World!");
[pool drain];
return 0;
}
********-----
@interface movie : NSObject {
@private
}
-(void)findinterestofnum1:(int)p num2:(int)n num3:(int)r;
@end
*******-------
#import "movie.h"
@implementation movie
-(void)findinterestofnum1:(int)p num2:(int)n num3:(int)r
{
int a ;
a= (p*n*r/100);
NSLog(@"interest value is =%d",a);
}
- (void)dealloc
{
[super dealloc];
}
@end
我试图找出方法是否已实施,如果不是,则应该打印它未实现
答案 0 :(得分:0)
@toddler,respondsToSelector只检查相应的对象是否可以响应该特定方法。它不会检查接口是否具有与之关联的定义,因为它是运行时检查。
如果您已从实现文件(.m文件)而不是接口中删除了代码,则在执行时会出现错误,并且您会发现BOOL sul为FALSE。