Question

Is there a way to create "Class" outlets?

The idea would be to instantiate those outlets from a Nib only once and share that with all instances.

My main doubt is how to mix

@property (...) IBOutlet ...
static ...
@syntetize/@dynamic ...
Was it helpful?

Solution

Use a singleton pattern.

The singleton instance can own your IBOutlets in the normal way and they will be created only once and shared.

OTHER TIPS

I'm not sure this is a good idea, but you can get the effect you are looking for by defining the per-instance setFoo/foo methods to deal with a shared value...

You can declare @property (...) IBOutlet foo and define:

static id sharedFoo;

-(void)setFoo:(id)newFoo {
    sharedFoo = newFoo;
}

-(id)foo {
    return sharedFoo;
}

This might not be a good idea because it isn't all that obvious what you have done, and the old adage of "if you lie to the computer, it will get you" could come into play.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top