I have been looking around for solutions on how to create a singleton pattern which is thread safe on ios. I came upon basically the same solutions over and over but when I init the object the pointer still says null. As you can tell from the screenshot.
It's pretty strange since nobody on the internet seems to have had this issue so far. I myself need to compare if the sharedInstance is initialized to enter a certain piece of code somewhere else and it will always tell me after init that it is nil.
What's this about? Anybody any clues? I want to understand! :D
Thanks in advance, cheers, Thor
// Why this is not a duplicate: // This question is not about the proper init it is about why the sharedInstance is not behaving like it should after. I still got the problem of not being able to compare it to nil or even have a comparison in the sharedInstance method to prevent from overwriting the singleton. How to prevent from overwriting would be my followup question? I even tried it with another BOOL which I set to true during the init. The result is, the if (!bool) will be seen as true although my debugger says bool==yes-> !bool should be false.
THE QUESTION: Why is my pointer to the instance returned properly and outside (on the caller methods side) results to nil? To make it clear a call from outside:
ControlSchemes *cs = [ControlSchemes sharedInstance];
will enter the code of sharedInstance have a valid pointer to a valid object in the return according to the debugger BUT will then have nil inside the cs after stepping over. Why?
//