Problem with implicit function declaration in object c

I'm trying to learn a little more about Objective-c, and at the moment I'm stuck. I had 4 errors, anyway. "Implicit function declaration", I googled, but I did not 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 

Lines

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

everyone says "Implicit function declaration"

Thanx in advance, Dietger

+4
source share
4 answers

I think this may be because you are mixing the syntax of C and Objective C.

Try:

 if (newFrequency > [self maxFMFrequency]) 
+2
source

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]) { 
+9
source

You mix methods and functions.

the code you call with

 if (newFrequency > maxFMFrequency()) { 

expects to see a function type declaration

 double maxFMFrequency() 

implemented as a C function - it will not be able to receive data from the object, so you need to use the method

the header declares the method as

 +(double)maxFMFrequency; 

but it needs to be called like

 if (newFrequency > [RadioStation maxFMFrequency]) 
+3
source

I had the same problem. sorted by changing a function call as follows

 //function declaration -(void) downloadPage:(NSString *)url; //function definition -(void) downloadPage:(NSString *)url { userOutput.text = url; } //and now the fixed call to downloadPage -(IBAction) onButtonOneClicked:(id) sender { userOutput.text = @"please wait..."; //fixed call to downloadPage [self downloadPage:[userInput text]]; } 
+1
source

Source: https://habr.com/ru/post/1336986/


All Articles