I had a question about declaring static variables for my Objective-C app.
Right now, I have two classes: FirstModel and SecondModel.
The implementation for FirstModel looks like:
The implementation for SecondModel looks like:
The goal is that whichever class I'm in, a method of that class can access staticString for the appropriate message.
The C texts that I'm looking at don't really explain this that well to me. Is this an appropriate use of the static declaration? Is static unnecessary because they are contained in separate files?
I've declared static variables in methods and functions before, but declaring static variables outside of methods or functions is a little new to me.
Right now, I have two classes: FirstModel and SecondModel.
The implementation for FirstModel looks like:
Code:
#import "FirstModel.h"
static NSString *staticString = @"This is the First Model.";
@implementation FirstModel
// Here is the code.
@end
The implementation for SecondModel looks like:
Code:
#import "SecondModel.h"
static NSString *staticString = @"This is the Second Model.";
@implementation SecondModel
// Here is the code.
@end
The goal is that whichever class I'm in, a method of that class can access staticString for the appropriate message.
The C texts that I'm looking at don't really explain this that well to me. Is this an appropriate use of the static declaration? Is static unnecessary because they are contained in separate files?
I've declared static variables in methods and functions before, but declaring static variables outside of methods or functions is a little new to me.