2
votes

I have this case where I just Call the init of Class I made this class is subclass of NSObject.

- (instancetype)initArray
{
    self = [super init];

    if (self) {
      //Do Some Logic
    }
return self;
}

This is my Call from the App Delegate

    CategoryLoader *categoryLoader = [[CategoryLoader alloc]initArray];

Whats driving me crazy is that:

  • Although it returns nil it goes into the if condition
  • It doesn't return nil on other computer with other Xcode

Please note that both Xcode's are 6.3

Solutions i tried:

  • Cleaned Cache of Xcode
  • Deleted the class and created a new one
  • Reinstalled Xcode

Here is a Screenshot of whats happening:

Screenshot

Any suggestions why could it be returning nil from NSObject and what can i do next ?

Thank you

2
Are you subclassing NSArray? If so please refer which methods should be overridden: developer.apple.com/library/mac/documentation/Cocoa/Reference/…. - hris.to
Yeah I have read this, But it doesn't solve my problem. - Mostafa Mohamed Raafat
You sure its really nil? Sometimes debugger displays it wrong. Try printing it out. - Jakub Vano
@JakubVano Yes its not nil !!!!!! the debugger returns nil while printing it out returned object address!! Thank you that helped me a lot. Can you please post it as answer so people would know that the watch is not always accurate! - Mostafa Mohamed Raafat

2 Answers

1
votes

NSObject’s implementation of init should never return nil. This is documented in the NSObject Class Reference: although slightly confusing, the key part is

The init method defined in the NSObject class does no initialization; it simply returns self.

If you are observing it retuning nil, either something is not setup how you expect (perhaps the class isn’t a direct subclass of NSObject), or you are somehow interpreting the results incorrectly, or there is something wrong at another level. The fact that you observe different results on different machines suggests it might be at another level, like Xcode, the operating system, or the hardware. I can’t help much there; try rebooting.

Also, your method ought to be named init not initArray. This is not a requirement but a very strong convention. You can read about Object Initialization in Apple’s Concepts in Objective-C Programming

1
votes

Ok. That was the problem:

The the scheme was on Release Mode. In this case the watch window displays nil in most of the objects. When I printed the value of self on NSLog it printed its value. The only difference between me and the other Xcode was the scheme.

So the solution is to edit the scheme of the project to be debug.

Thank you for your support