ios - 实现不完整 - Xcode 警告

标签 ios

我刚刚开始 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

最佳答案

你的问题是你的界面说有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

关于ios - 实现不完整 - Xcode 警告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15036783/

相关文章:

ios - 无法使用 XCode 7.0 Beta、iOS 8.3 和 aws-ios-sdk-2.2.0 识别 AWSDynamoDB

ios - 从 Chrome 打开 iTunes 的链接

ios - Swift 将长代码转换为短代码

ios - 创建使用外部 Pod 的自定义 Pod

ios - Touch drag enter 如何工作?

ios - 从 TableView 行获取 ObjectId(解析)

ios - 搜索整个 UITableView 单元格的 UISearchBar

ios - 在 Objective c 中解析 RTF

ios - 如何在用户退出时保存当前选项卡栏项目并在重新启动时重新加载到该项目?

iphone - 开始/结束外观转换的不平衡调用