I’ve created a singleton (called sharedinstance) in my appDelegate, and ideally I want to access it from all other objects/instances in my code, but everytime I want to access a method/var in it, I’m having to do
Game *sharedInstance = [Game sharedInstance];
In whatever method in any other instance to be able to do something like..
[sharedInstance.myMethod]
I tried putting
Game *sharedInstance;
in the .h file of the other instance, but when I run the code, Game = 0. I just tried putting
Game *sharedInstance = [Game sharedInstance];
In the other instances init method but that’s not helping either.
Your problem is not really related to singletons, it’s just a matter of not knowing how to declare and use variables and methods. You need to get the instance of Game to call a method on it, you do this with [Game sharedInstance]. You then need to either call the method on it, or assign it to an instance variable to call a method later.
i.e. either:
or