I have a singleton I implement in this way:
PhotoViewController* sharedSingleton = [PhotoViewController sharedManager];
I know that to launch a method I have to do [sharedSingleton method];
but what if I want to change an integer declared in the PhotoViewController.h file as NSInteger* tagNumber, hoe can I do that? I tried this:
[sharedSingleton.tagNumber = 1];
but it doesn’t work!
EDIT:
error: property tagNUmber not found on object of type photoViewController
@interface PhotoViewController : UIViewController{
BOOL newMedia;
UIPopoverController *popoverController;
DBRestClient *restClient;
NSInteger* tagNumber;
}
+ (PhotoViewController *) sharedManager;
@end
Singletons are regular objects. The only difference is that only one instance will be created from the class.
If you aren’t able to set the tagNumber it is likely that some other type of coding error is happening… perhaps the tagNumber property was declared in a class extension, making the accessor/mutator methods private?
If you edit your question with how the tagNumber is declared, and also include the error message you are getting, I’ll be able to edit this answer and give you more specific advice.
EDIT: …and yes, definitely double check to make sure you didn’t declare the NSInteger to be a pointer… an NSInteger is a scalar type (so it takes a direct value, and doesn’t use the dereference ‘*’ operator).
I suggest using properties instead of accessing the instance variables directly:
Then set the variable without the brackets as: