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.

Matthias Bauch
  • 89,811
  • 20
  • 225
  • 247
Ruli
  • 121
  • 6

2 Answers2

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.

Grzegorz Krukowski
  • 18,081
  • 5
  • 50
  • 71
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.

Phillip Mills
  • 30,888
  • 4
  • 42
  • 57