我刚刚开始使用iOS开发,并且由于警告而有点卡住了。构建成功但这个警告困扰着我。我检查了一些其他的答案,但无法弄清楚出了什么问题。
Waring - 不完整的实施
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 :(得分:3)
您的问题是您的界面显示有real
和imaginary
方法,但您尚未实施这些方法。更好的是,让编译通过将它们定义为属性来合成real
和imaginary
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
答案 1 :(得分: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;
_是实例成员。
答案 2 :(得分: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