8

I'm trying to declare a function within another function. So here's part of my code: ViewController.m

- (void)updatedisplay{
    [_displayText setText:[NSString stringWithFormat:@"%d", counter]];

}

- (IBAction)minus1:(id)sender {
    counter--;
    updatedisplay();
}

ViewController.h

- (IBAction)minus1:(id)sender;
- (void)updatedisplay;

Which returned me the error of "Implicit declaration of function "..." is invalid in C99".

Result: https://i.stack.imgur.com/XGevK.png

I've found that people have encountered similar problem, but as a newbie I didn't really know what to do next. Thanks for your help! :)

Implicit declaration of function '...' is invalid on C99

Community
  • 1
  • 1
Rouvis
  • 159
  • 1
  • 1
  • 10
  • 1
    first learn some basic things related to objective see after that you can implement programs..http://cocoadevcentral.com/d/learn_objectivec/ – Balu Jul 22 '13 at 05:19

4 Answers4

14

You are not declaring a function; but a instance method, so to call it you must send it as a message to self;

[self updatedisplay];

EDIT

As @rmaddy pointed out (thanks for that) it is declared as instance method not class method. To make the things clear;

- (return_type)instance_method_name.... is called via 'self' or pointer to object instance.
+ (return_type)class_method_name.... is called directly on the class (static).

iPatel
  • 46,010
  • 16
  • 115
  • 137
ludesign
  • 1,353
  • 7
  • 12
7

Problem

updatedisplay();

solution

[self updatedisplay];

cause

- (void)updatedisplay;

is a class method available for that class.So you have to call from the class to have the method available for you.

Lithu T.V
  • 19,955
  • 12
  • 56
  • 101
4

That is because you defined your function as a instance method, not a function.

So use it like

- (IBAction)minus1:(id)sender {
    counter--;
    [self updatedisplay]; // Change this line
}
βhargavḯ
  • 9,786
  • 1
  • 37
  • 59
2

write this way :

[self updatedisplay];
KDeogharkar
  • 10,939
  • 7
  • 51
  • 95