Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Calling a class method from an instance method [closed]

Tags:

objective-c

I want to call a class method from an instance method to use its return value.

This is my class method

+(double) minFMFrequency {

    return 88.3;
}

and this is my instance method

-(void) chackFrequency {

    switch (band) {
        case 'F':
            if (self.frequency > Value obtained from class method )
                frequency=107.9;
            break;

        default:
            break;
    }

}

band and frequency are instance variables.

like image 755
shay nagar Avatar asked Mar 18 '26 21:03

shay nagar


1 Answers

+(void)classMethod
{
    [self anotherClassMethod]; // in a class method, self refers to the class
}

-(void)instanceMethod
{
    [self anotherInstanceMethod]; //in an instance method self refers to the object, or instance 

    [[self class] classMethod]; //to call a class method from an instance send the instance the class message

}

so in your case: [[self class] minFMFrequency];

like image 111
vikingosegundo Avatar answered Mar 21 '26 09:03

vikingosegundo