2013-02-23 76 views
2

我刚开始使用iOS开发,并且由于警告而停滞不前。构建成功,但这个警告正在困扰着我。我查了一些其他的答案,但无法弄清楚什么是错的。不完整的实现 - Xcode警告

华林 - 未完全执行

Complexnumbers.h

#import <Foundation/Foundation.h> 

@interface ComplexNumbers : NSObject 

-(void) setReal: (double)a; 
-(void) setImaginary: (double)b; 
-(void) print; // display as a + bi 

-(double) real; 
-(double) imaginary; 

@end 

Complexnumbers.m

#import "ComplexNumbers.h" 

@implementation ComplexNumbers // Incomplete implementation 

{ 
double real; 
double imaginary; 
} 

-(void) print 
{ 
    NSLog(@"%f + %fi",real,imaginary); 
} 
-(void) setReal:(double)a 
{ 
    real = a; 
} 
-(void) setImaginary:(double)b 
{ 
    imaginary = b; 
} 

@end 
+0

看来你想有两个*变量*名为'真正'和'虚构',是否正确?那么,你有2 *函数叫做'real'和'imaginary',并且因为它们没有在你的'.m'文件中作为函数实现,所以你会得到这个警告:)。遵循提供给你的变量提供'@ property'和'@ synthesize'的答案。 – Mxyk 2013-02-23 03:50:17

+0

更正Mike,一开始有点混乱。经验教训虽然:) – vDog 2013-02-23 04:03:12

回答

2

您还没有实现这些属性的getter:

-(double) real; 
-(double) imaginary; 

呦ü可以实现它们:

-(double) real { return _real; } 
-(double) imaginary { return _imaginary; } 

或者让编译器为你做它通过声明他们作为头属性:

@property(nonatomic) double real; 
@property(nonatomic) double imaginary; 

而在.m文件:

@synthesize real = _real, imaginary = _imaginary; 

_是实例成员。

+0

谢谢你的答案杰夫。我用了一个下划线,并将它们重新声明为属性,它的工作方式就是它应该的。 – vDog 2013-02-23 04:01:29

3

你的问题是,你的界面说有realimaginary方法,但你还没有实现这些。更重要的是,让编译通过定义它们为属性合成为您realimaginary setter和getter方法,你的代码被大大简化:

@interface ComplexNumbers : NSObject 

@property (nonatomic) double real; 
@property (nonatomic) double imaginary; 

-(void) print; // display as a + bi 

@end 

@implementation ComplexNumbers 

-(void) print 
{ 
    NSLog(@"%f + %fi", self.real, self.imaginary); 
} 

@end 
0

试试这个,

#import "ComplexNumbers.h" 

@implementation ComplexNumbers // Incomplete implementation 

{ 
double real; 
double imaginary; 
} 

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

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

{ 
imaginary = b; 
} 
-(double) real 
{ 
    return real; 
} 
-(double) imaginary 
{ 
    return imaginary; 
} 

@end 
+0

你有一个错误。该ivars没有领先的下划线。 – rmaddy 2013-02-23 03:54:13