初学者:XCode中的Objective C错误

时间:2014-11-09 19:36:00

标签: objective-c xcode

编辑:感谢Onik IV和Rob Bajorek !!

我通过一本名为Objective C for Absolute Beginners的书来学习Obj C.我应该为无线电台创建一个代码并遇到一些错误。这有点令人困惑,因为我编写的代码与书中所示的代码相同。

标题文件:https://github.com/williyam/XCode-Projects/blob/master/radiostations/RadioStations/RadioStations.h

方法文件:https://github.com/williyam/XCode-Projects/blob/master/radiostations/RadioStations/RadioStations.m

XCode将这些错误抛在方法文件中:

  • 第11行' setFrequency',' name',' setName'和'频率'找不到
  • 第33行无效的参数类型' NSString *'一元表达

标题

#import <Foundation/Foundation.h>

@interface RadioStations : NSObject{
    NSString* name;
    double frequency;
    NSUInteger band;
}

+ (double)minAMFrequency;
+ (double)maxAMFrequency;
+ (double)minFMFrequency;
+ (double)maxFMFrequency;

- (id)initWithName: (NSString*)newName atFrequency:(double)newFrequency;
- (NSString*)name;
- (void)setName: (NSString*)newName;
- (double)frequency;
- (void)setFrequency:(double)newFrequency;


@end

方法

#import "RadioStations.h"

@implementation RadioStations
+ (double)minAMFrequency{
    return 520.0;
}
+ (double)maxAMFrequency{
    return 1610.0;
}
+ (double)minFMFrequency{
    return 88.3;
}
+ (double)maxFMFrequency{
    return 107.9;
}

- (id)initWithName: (NSString*)newName atFrequency:(double)newFrequency {
    self = [super init];
    if(self!=nil){
        name = newName;
        frequency = newFrequency;
    }
    return self;

- (NSString*)newName{
    return name;
}
- (void)setName:(NSString*)newName{
    name = newName;
}
- (double)frequency{
    return frequency;
}
- (void)setFrequency: (double)newFrequency{
    frequency = newFrequency;
}
}

    @end

1 个答案:

答案 0 :(得分:0)

我看到了几个错误:

  #import "RadioStations.h"

 .....
// Change newName to name. (like in header says)


// Change this  - (NSString*)newName{
- (NSString*)name{

return name;
 }


......

- (void)setFrequency: (double)newFrequency{
frequency = newFrequency;
}
// This must be delete }

@end