So I’m finding that I’m using a singleton User class to access global variables throughout an iphone app. In some cases I use the instance in almost all the methods within a class. So in the first few lines of each method I have statement such as:
User *user = [User sharedManager];
This is obviously not a very DRY implementation. My question is: instead of repeating this statement in all the methods I need to access User can’t I just instantiate this once, say in the initializer, and then set a property equal to this pointer such as:
-(id)init {
.....
self.sharedUser = [User sharedManager];
....
}
and then reference this property in each method instead of instantiating the singleton?
sure, you can do this. There might be (small) issues with code readability, but there’s nothing wrong with this.