Re: Increment object property
Re: Increment object property
- Subject: Re: Increment object property
- From: Keary Suska <email@hidden>
- Date: Wed, 22 Oct 2008 14:19:38 -0600
- Resent-date: Wed, 22 Oct 2008 14:20:13 -0600
- Resent-from: Keary Suska <email@hidden>
- Resent-message-id: <email@hidden>
- Resent-to: "Cocoa-Dev (Apple)" <email@hidden>
On Oct 22, 2008, at 2:10 PM, email@hidden 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 (email@hidden)
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:
This email sent to email@hidden