• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Increment object property
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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

References: 
 >Increment object property (From: email@hidden)

  • Prev by Date: Re: Rotating a QTMovie doesn't work the way it used to
  • Next by Date: Re: Memory Leaks in CocoaEcho Sample
  • Previous by thread: Re: Increment object property
  • Next by thread: another n00b question -- how to find a memory leak
  • Index(es):
    • Date
    • Thread