Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Problem with implicit declaration of function in objective c

I trying to learn a bit more about Objective-c, and at the moment i'm stuck. I got 4 errors, all the same. "Implicit declaration of function", I googled it but i didn't find a solution.

RadioStation .h

#import <Cocoa/Cocoa.h>
@interface RadioStation : NSObject {
  NSString* name;
  double frequency;
  char band;
}
+(double)minAMFrequency;
+(double)maxAMFrequency;
+(double)minFMFrequency;
+(double)maxFMFrequency;
-(id)initWithName:(NSString*)newName atFrequency:(double)newFrequency withBand:(char)newBand;
-(NSString*)name;
-(double)frequency;
-(char)band;
-(void)setName:(NSString*)newName;
-(void)setFrequency:(double)newFrequency;
-(void)setBand:(char)newBand;
@end

RadioStation .m

#import "RadioStation.h"

@implementation RadioStation
+(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 withBand:(char)newBand{
 self = [super init];
 if(self != nil){
  name = [newName retain];
  band = newBand;
  if (band == 'F') {
   if (newFrequency > maxFMFrequency()) {
    frequency = maxFMFrequency();
   }else if (newFrequency < minFMFrequency()) {
    frequency = minFMFrequency();
   }else {
    frequency = newFrequency;
   }

  }else if (band == 'A') {
   if (newFrequency > maxAMFrequency()) {
    frequency = maxAMFrequency();
   }else if (newFrequency < minAMFrequency()) {
    frequency = minAMFrequency();
   }else {
    frequency = newFrequency;
   }
  }
 }
 return self;
}
@end

The lines

if (newFrequency > maxFMFrequency()) {
if (newFrequency < minFMFrequency()) {
if (newFrequency > maxAMFrequency()) {
if (newFrequency < minAMFrequency()) {

all say "Implicit declaration of function"

Thanx in advance, Dietger

like image 417
Madi Avatar asked Dec 07 '22 23:12

Madi


1 Answers

These are class methods so you will need to change each of them as follows:

if (newFrequency > [RadioStation maxFMFrequency]) {
if (newFrequency < [RadioStation minFMFrequency]) {
if (newFrequency > [RadioStation maxAMFrequency]) {
if (newFrequency < [RadioStation minAMFrequency]) {
like image 99
theChrisKent Avatar answered Feb 08 '23 22:02

theChrisKent