Re: Increment object property
Re: Increment object property
- Subject: Re: Increment object property
- From: Charles Steinman <email@hidden>
- Date: Wed, 22 Oct 2008 14:53:57 -0700 (PDT)
--- On Wed, 10/22/08, email@hidden <email@hidden> wrote:
> Newbie question, Is it possible to have an object property
> that
> increments everytime an object is instantiated?
Simplest solution: Just increment a static int and insert that into your string. Fancy it up as appropriate to your situation.
@interface Foo : NSObject {
NSString *name;
}
@property (copy,readwrite) NSString *name;
@end
#import "foo.h"
@implementation Foo
@synthesize name;
- (id) init {
static unsigned documentCount = 1;
self = [super init];
if (self != nil) {
self.name = [NSString stringWithFormat:@"untitled%u", count++];
}
return self;
}
@end
Cheers,
Chuck
_______________________________________________
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