Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Incomplete implementation (xcode mistake?)

// 9.1.h

#import <Foundation/Foundation.h>


@interface Complex : NSObject 
{

    double real;
    double imaginary;

}

@property double real, imaginary;
-(void) print;
-(void) setReal: (double) andImaginary: (double) b;
-(Complex *) add: (Complex *) f;

@end

#import "9.1.h"


@implementation Complex

@synthesize real, imaginary;

-(void) print
{
    NSLog(@ "%g + %gi ", real, imaginary);
}

-(void) setReal: (double) a andImaginary: (double) b
{
    real = a;
    imaginary = b;
}

-(Complex *) add: (Complex *) f
{
    Complex *result = [[Complex alloc] init];

    [result setReal: real + [f real] andImaginary: imaginary + [f imaginary]];

    return result;

}
@end

On the final @end line, Xcode is telling me the implementation is incomplete. The code still works as expected, but I'm new at this and am worried I've missed something. It is complete as far as I can tell. Sometimes I feel like Xcode hangs on to past errors, but maybe I'm just losing my mind!

Thanks! -Andrew

like image 680
jag Avatar asked May 18 '11 18:05

jag


1 Answers

In 9.1.h, you have missed an 'a'.

-(void) setReal: (double) andImaginary: (double) b;
//                       ^ here

The code is still valid, because in Objective-C a selector's part can have no name, e.g.

-(id)initWithControlPoints:(float)c1x :(float)c1y :(float)c2x :(float)c2y
//                                    ^           ^           ^

these methods are called as

return [self initWithControlPoints:0.0f :0.0f :1.0f :1.0f];
//                                      ^     ^     ^

and the selector name is naturally @selector(initWithControlPoints::::).

Therefore, the compiler will interpret your declaration as

-(void)setReal:(double)andImaginary
              :(double)b;

since you have not provided the implementation of this -setReal:: method, gcc will warn you about

warning: incomplete implementation of class ‘Complex’
warning: method definition for ‘-setReal::’ not found

BTW, if you just want a complex value but doesn't need it to be an Objective-C class, there is C99 complex, e.g.

#include <complex.h>

...

double complex z = 5 + 6I;
double complex w = -4 + 2I;
z = z + w;
printf("%g + %gi\n", creal(z), cimag(z));
like image 62
kennytm Avatar answered Sep 22 '22 23:09

kennytm