I think what you may be looking for is the singleton/shared pattern, which allows any code to access a particular instance of a class without being passed that instance.
This model is used throughout Cocoa. For example, NSFileManager
has a class method defaultManager
which returns the shared instance of the class. You call an instance method on this shared instance by first invoking defaultManager
, so for example to call the instance method isDeletableFileAtPath
you write:
[[NSFileManager defaultManager] isDeletableFileAtPath:path]
In your case your DoThis
becomes:
+ (void) DoThis
{
EvDudeClass *shared = [EvDudeClass sharedInstance];
[shared.textView setString:@"qwertyasdfzxcvb."];
[shared.textView setNeedsDisplay:YES];
}
And you need to add a sharedInstance
method to your class. There a number of ways to do this depending on how you wish to use your class - Is it a singleton? Do you just need one shared instance and other non-shared ones? Do you just want to share the instance created in the NIB? As you mention IBOutlet
here is an implementation which does the latter:
static EvDudeClass *privateSharedInstance = nil;
- (void) awakeFromNib
{
privateSharedInstance = self; // save this instance so it can be shared
// other init stuff
}
+ (EvDueClass *)sharedInstance { return privateSharedInstance; }