2013-02-23 79 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