2

When I try to call a function in a +(void)function it is not working.

example:

+(void) publicfunction {
[self otherFunction];
}

-(void) otherFunction{
self.scene.view.pause = YES
}

but I can't call "otherFunction" inside of +(void)publicFunction.

0

2 Answers 2

3

Use:

+(void) publicfunction {
    [YourClassName otherfunction];
}

"+" is static method it neither require an instance nor can they implicitly access the data (or this, self, Me, etc.) of such an instance

And you need to change your other function class to "+" as well.

But if you need an access to your "self" properties. you should not use static methods - instead keep reference to your object and make those as normal methods.

Sign up to request clarification or add additional context in comments.

7 Comments

This is also no working =/ Classname otherfunction
you need to replace "YourClassName" with your class name - i don't know what is it
yes i know, I did but it is not working at all. Do I have to write something in the .h file or so?
You need to make other function + as well.
What about the parameter in that function + ?
|
2

You can't call an instance method like - (void)otherFunction unless you have an instance of the class.

Often, methods (not "functions") such as publicFunction return instances of their type. In those cases, they create an object and prepare it as necessary. Consider the [NSString stringWith...] style of method.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.