On Oct 22, 2008, at 2:10 PM, [EMAIL PROTECTED] wrote:

Newbie question, Is it possible to have an object property that increments everytime an object is instantiated?

You can have a static variable defined in the implementation file, and it will be persistent across the class, but will be invisible to subclasses, which is a drawback. Or you could have a class method with a static stack var. You could have a global var.

@interface foo : NSObject {
        NSString        *name;
}
@property (copy,readwrite) NSString *name;
@end

#import "foo.h"
@implementation foo
- (id) init {
        self = [super init];
        if (self != nil) {
                [self setName:@"untitled1"];
        }
        return self;
}
@synthesize name;
@end

I have an NSTableColumn that is bound to foo.name. An NSArrayController looks after adding and removing the foo objects. How can I make the name property increment from untitled1, untitled2, untitled3... etc as the objects are added to the array?

Perhaps also have an initWithName: method, and subclassing the nsarraycontroller so you have control over object creation, then you could use [NSString stringWithFormat:@"untitled%i", [[self arrangedObjects] count]].

HTH,

Keary Suska
Esoteritech, Inc.
"Demystifying technology for your home or business"

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to