Understanding Objective-C Volume Issues

The following is a snippet from the View Controller implementation:

- (void)myOtherAwesomeMethod
{
    [self myAwesomeMethod]; // Compile ERROR here: Receiver type for instance message does not declare a method with selector
}

- (void)myAwesomeMethod
{
    NSLog(@"%@", @"Calling my awesome method...");
}

- (void)viewDidLoad
{
    [self myAwesomeMethod];

    [self myOtherAwesomeMethod];
}

I do not have a method myAwesomeMethoddeclared in my header file, but why can I call myAwesomeMethodin viewDidLoad, but not in myOtherAwesomeMethod?

I know that the solution to this error is to declare a method in my header file, but I would like to understand why this is happening.

+5
source share
2 answers

In C rule: you must declare it before using it.

Files are compiled from top to bottom. So here is what happens in your code:

  • @interface . , , .

    :

  • myAwesomeMethod. , . NSLog, , Apple.

    : myAwesomeMethod

  • viewDidLoad; . myAwesomeMethod, ! myOtherAwesomeMethod. !

    , . , ( ). ( , , , ). , id .

    : myAwesomeMethod

  • , myOtherAwesomeMethod. . , myAwesomeMethod, . , .

    : myAwesomeMethod, myOtherAwesomeMethod

, Java, , , Java , C. Java ; , , . , , , , .

C - . , , ; , , . , .

Objective-C / Objective-C , / , . , , , .

+11

, , viewDidLoad.

, " DECLARE" . , ( ).. .. .

, , . , .

0

All Articles