tags:

views:

31

answers:

2

My Class

@interface sample:NSObject{

   double x;

   double y;

}
@property double x;

@property double y;

-(sample *)initWithX: (double)x andY:(double) Y;


@implementation

@synthesize x,y

-(sample *) initWIthX: (double)x andY:(double)y{

    self = [super init];

    if(self) 
    {

      self.x = x;

      self.y = y; 

    }
     return self;

}

-(BOOL)isEqual:(id)other{

 if(other == self)
   return YES;
 if(!other || ![other isKindOfClass:[self class]])
   return NO;
 return [self isEqualToSample:other];  
}


-(BOOL)isEqualToSample:(sample *) other{

 if(self == other)    
   return YES;

 if (!([self x] ==[other x])) 
   return NO;

 if (!([self y] ==[other y]))   
   return NO;

   return YES;
}

at

return [self isEqualToSample:other]; it shows warning: 'sample' maynot respont to '-isEqualToSample'. return makes integer from pointer without a cast.

+2  A: 

you must declare isEqualToSample prior to your use of it. otherwise, the compiler assumes the selector's signature takes/returns id.

so you can declare it in the header, in a private category, or place the implementation before isEqual:

Justin
or a class continuation.
Graham Lee
thanks a lot ...
Ravi Teja
@Ravi you're welcome.
Justin
+1  A: 

Unrelated to the warning, but when overriding -isEqual: you must also override hash such that if [a isEqual: b] then [a hash] == [b hash].

Graham Lee
thanks i will implement it
Ravi Teja