我刚刚开始 iOS 开发,由于警告而有点卡住了。构建成功,但这个警告让我很困扰。我检查了其他一些答案,但无法找出问题所在。
Waring - 实现不完整
复数.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
复数.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
最佳答案
你的问题是你的界面说有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
关于ios - 实现不完整 - Xcode 警告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15036783/