0

this is the problem:

myObject.h

@interface myObject
- (void) Init;
- (void) doStuffs;
- (void) Final;
+ (NSData*) staticMethod: (NSString*) filePath
@end

myObject.m

@implementation myObject

- (void) Init {
...
}

- (void) doStuffs {
...
}

- (void) Final {
...
}

+ (NSData*) staticMethod: (NSString*) filePath {
    myObject *objInstance;

    [objInstance Init];
    [objInstance doStuffs];
    [objInstance Final];
}
@end

When calling Init, doStuffs and Final on the static method, the instance methods are not called; any idea?

For short: I need to call instance method from a static method of the same class...

Thank you for helping.

1
  • 1
    alloc/init of objInstance isn't done. Commented Mar 23, 2016 at 18:25

2 Answers 2

4

You haven't created an instance of myObject. So, assuming ARC, you're calling on nil. Calling on nil doesn't do anything.

So:

myObject *objInstance = [[myObject alloc] init];
Sign up to request clarification or add additional context in comments.

Comments

1

If you don't initialize objInstance, it'll be nil and those calls won't do anything. Allocate and initialize objInstance first. You can also check objInstance for nil before calling those methods and you'll see it is nil.

This is one of the trickier things about Objective-C. Java would throw a NullPointerException if you tried something like this. Objective-C silently keeps chugging along!

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.